diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-05-04 17:09:51 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-05-04 17:09:51 +0200 |
| commit | 0fbc92e0c4c07d61da55d0bbb3cadd55f51dc4d7 (patch) | |
| tree | 4be569ab0f86370fe9044a9b13d69c858c980de0 /addons/mrp/mrp.py | |
| parent | 858188f1a2a2207cf93cc0f2d0d2deb08bb7dbf6 (diff) | |
| parent | 1e86774207d09c901c61b148c5c0c23a511aa282 (diff) | |
[MERGE] forward port of branch saas-10 up to 1e86774
Diffstat (limited to 'addons/mrp/mrp.py')
| -rw-r--r-- | addons/mrp/mrp.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 86da1d7cab1..aee94497cd8 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -804,13 +804,7 @@ class mrp_production(osv.osv): return True def _compute_costs_from_production(self, cr, uid, ids, context=None): - """ Generate workcenter costs and rectify the value of the quant - - Must be called at the end of the production. - The value of the quant was not possible to compute before the end of - the manufacturing order due to the cost of raw manterial and production - costs. The price of the quant was not set in get_price_unit. - """ + """ Generate workcenter costs in analytic accounts""" for production in self.browse(cr, uid, ids): total_cost = self._costs_generate(cr, uid, production) @@ -957,6 +951,16 @@ class mrp_production(osv.osv): total_cost += sum([x.inventory_value for x in consumed_move.quant_ids if x.qty > 0]) return total_cost + def _calculate_workcenter_cost(self, cr, uid, production_id, context=None): + """ Compute the planned production cost from the workcenters """ + production = self.browse(cr, uid, production_id, context=context) + total_cost = 0.0 + for wc_line in production.workcenter_lines: + wc = wc_line.workcenter_id + total_cost += wc_line.hour*wc.costs_hour + wc_line.cycle*wc.costs_cycle + + return total_cost + def action_produce(self, cr, uid, production_id, production_qty, production_mode, wiz=False, context=None): """ To produce final product based on production mode (consume/consume&produce). If Production mode is consume, all stock move lines of raw materials will be done/consumed. @@ -1012,17 +1016,24 @@ class mrp_production(osv.osv): total_consume_moves.append(extra_move_id) if production_mode == 'consume_produce': + # add production lines that have already been consumed since the last 'consume & produce' + last_production_date = production.move_created_ids2 and max(production.move_created_ids2.mapped('date')) or False + already_consumed_lines = production.move_lines2.filtered(lambda l: l.date > last_production_date) + total_consume_moves += already_consumed_lines.ids + price_unit = 0 for produce_product in production.move_created_ids: is_main_product = (produce_product.product_id.id == production.product_id.id) and production.product_id.cost_method=='real' if is_main_product: total_cost = self._calculate_total_cost(cr, uid, total_consume_moves, context=context) - price_unit = total_cost / production_qty_uom + production_cost = self._calculate_workcenter_cost(cr, uid, production_id, context=context) + price_unit = (total_cost + production_cost) / production_qty_uom + lot_id = False if wiz: lot_id = wiz.lot_id.id qty, remaining_qty = self._calculate_produce_line_qty(cr, uid, produce_product, production_qty_uom, context=context) - if is_main_product: + if is_main_product and price_unit: stock_mov_obj.write(cr, uid, [produce_product.id], {'price_unit': price_unit}, context=context) new_moves = stock_mov_obj.action_consume(cr, uid, [produce_product.id], qty, location_id=produce_product.location_id.id, restrict_lot_id=lot_id, context=context) |
