Debian Codegraph @

addons/mrp_subcontracting_purchase/models/account_move_line.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import models
4
5
6 class AccountMoveLine(models.Model):
7 _inherit = 'account.move.line'
8
9 def _get_price_unit_val_dif_and_relevant_qty(self):
10 price_unit_val_dif, relevant_qty = super()._get_price_unit_val_dif_and_relevant_qty()
11 if self.product_id.cost_method == 'standard' and self.purchase_line_id:
12 components_cost = 0
13 subcontract_production = self.purchase_line_id.move_ids._get_subcontract_production()
14 valuation_date = subcontract_production.move_raw_ids and max(subcontract_production.move_raw_ids.mapped('date')) or self.date
15 components_cost = self.company_currency_id._convert(
16 sum(subcontract_production.move_raw_ids.mapped('value')),
17 self.currency_id, self.company_id, valuation_date, round=False
18 )
19 qty = sum(mo.product_uom_id._compute_quantity(mo.qty_producing, self.product_uom_id) for mo in subcontract_production if mo.state == 'done')
20 if not self.product_uom_id.is_zero(qty):
21 price_unit_val_dif = price_unit_val_dif + components_cost / qty
22 return price_unit_val_dif, relevant_qty
23
24 def _get_stock_moves(self):
25 moves = super()._get_stock_moves()
26 finished_moves = set()
27 for m in moves:
28 if mo := m._get_subcontract_production():
29 finished_moves |= set(mo.move_finished_ids.filtered(lambda mf: mf.product_id == m.product_id).ids)
30 return moves | self.env['stock.move'].browse(finished_moves)