[FIX] mrp: Post inventory button without finished product

Let's consider P1, P2 and P3 with a cost=1$, three stockable products where
P1 and P2 are in the same product category PC1 with a Stock valuation
account = SVA1 and P3 is in the product category PC2 with a Stock valuation
accout = SVA2. PC1 and PC2 are set with costing method in real price and
Inventory valuation = perpetual(automated).

Steps to reproduce this issue:

-Create a BOM where P3 is composed by 1 P1 and 1 P2
-Create a PO for P1 and P2 with a cost of 5$ for each one
-Create a MO to produce 1 P3
-Check availability
-Insert manually the consumed product(1 P1 and 1 P2)
-The button "Post Inventory" appeared, clicked on it
-Check the general ledger, two moves with debit=5$ has been created
for P1 and P2 in PC1(it's ok)
-Produce the MO and click on "Post Inventory" again
-Check the general ledger, two moves have been created, one with a credit of 2$
on PC1 and one of debit of 2$ on PC2(it was wrong)

The expected moves for the last step is:
a credit of 10$ on PC1 and a debit of 10$ on PC2 because the purchase price must be
considered as P1 and P2 are in real price.

NB: Everything is ok if the button "Post Inventory" is clicked after the production.

opw:741748
This commit is contained in:
Goffin Simon
2017-06-07 14:35:37 +02:00
parent 7b21016760
commit 2332df6bc7
3 changed files with 11 additions and 2 deletions
+5 -2
View File
@@ -208,8 +208,11 @@ class MrpProduction(models.Model):
@api.depends('move_raw_ids.quantity_done', 'move_finished_ids.quantity_done')
def _compute_post_visible(self):
for order in self:
order.post_visible = any(order.move_raw_ids.filtered(lambda x: (x.quantity_done) > 0 and (x.state not in ['done', 'cancel']))) or \
any(order.move_finished_ids.filtered(lambda x: (x.quantity_done) > 0 and (x.state not in ['done', 'cancel'])))
if order.product_tmpl_id._is_cost_method_standard():
order.post_visible = any((x.quantity_done > 0 and x.state not in ['done', 'cancel']) for x in order.move_raw_ids) or \
any((x.quantity_done > 0 and x.state not in ['done' 'cancel']) for x in order.move_finished_ids)
else:
order.post_visible = any((x.quantity_done > 0 and x.state not in ['done' 'cancel']) for x in order.move_finished_ids)
@api.multi
@api.depends('workorder_ids.state', 'move_finished_ids')
+3
View File
@@ -416,6 +416,9 @@ class ProductTemplate(models.Model):
relation="stock.location.route", string="Category Routes",
related='categ_id.total_route_ids')
def _is_cost_method_standard(self):
return True
def _compute_quantities(self):
res = self._compute_quantities_dict()
for template in self:
+3
View File
@@ -51,6 +51,9 @@ class ProductTemplate(models.Model):
def _compute_cost_method(self):
self.cost_method = self.property_cost_method or self.categ_id.property_cost_method
def _is_cost_method_standard(self):
return self.property_cost_method == 'standard'
@api.one
def _set_cost_method(self):
return self.write({'property_cost_method': self.cost_method})