This started from Magma's answer, and I wanted to prove it. I start with a simplification of the problem and analyze the cases.
I finish by offering a completely different approach.
First, Replace the weights with single weight equivalents. These are 12, 10, 4, 2. with the provision that we must use one and only one.
Secondly, The weight always goes on the left otherwise we just have a symmetrical cases.
L + W = R // balance
L + R = C // Total Coffee
L + L + W = C (Sub Balance in Total Coffee)
L = (C-W)/2
R = C - L
For our first trial, C = 52 or 0, and only one of these is significant.
C W L R Config
52 12 20 32 7+4+1
52 10 21 31 7+4-1
52 4 24 28 7+1-4
52 2 25 27 7-1-4
The L and R columns are all the possible measurements we can get from one trial. If we were to put the weight on the right side, simply walk around the scales and it becomes left.
Assume the 13 + weight pounds will end up in L (Symmetry again)
13 = (C-W)/2
26 = (C-W)
By inspection, all the values in the L column are too small satisfy this constraint.
Also, since 26 is even, and all Ws are even, we are left with 32 and 28 as candidates.
Using 32, we can get C-W as 20,22,28,30 -- None of these are 26
Using 28, we can get C-W as 16,18,24,26
So, For our first weighing, we get 24 lbs of coffee and 7+1 pounds of weight in the left tray, and 28 pounds of coffee and 4 lbs of weigh in the right.
Put the 24 lbs of coffee back in the bag.
For our second trial, We have 13 coffee + 7 w in the left and 15 coffee and (1 + 4) w in the right.
Alternately, if we want 13 pounds in the right,
13 = C - (C - W)/2
26 = 2C - C + W
26 = C + W
Similarly to above, we end up using 24 pounds of Coffee and 2 pounds of weight i.e. 11 + 7 = 13 + (4 + 1)
Then I checked Magma's alternate, and it is the only solution of this form.
But, I came up with a different approach that may be interesting,
Directly weigh out 12 lbs of coffee. Put it in the weightless sales bag.
In the left tray, put the 12 lb bag of coffee, and 7 lbs of weight.
In the right tray put the remaining 5 lbs of weight. Now add all the coffee from the bulk bag (40 lbs) to balance the scales.
You will end up with 13 loose, 12 bagged and 7 weight = 32lbs on the left. There will be 27 loose + 5 weight = 32 on the right.
Now, dump the sales bag into the bulk bag. Put the 13 pounds of coffee from the left tray in the sales bag and close the deal!