Debian Codegraph @

addons/stock_landed_costs/models/stock_move.py

raw symbols SCIP
1 from odoo import models
2
3
4 class StockMove(models.Model):
5 _inherit = "stock.move"
6
7 def _get_landed_cost(self, at_date=None):
8 domain = [('move_id', 'in', self.ids), ('cost_id.state', '=', 'done')]
9 if at_date:
10 domain.append(('cost_id.date', '<=', at_date))
11 landed_cost_group = self.env['stock.valuation.adjustment.lines']._read_group(domain, ['move_id'], ['id:recordset'])
12 return dict(landed_cost_group)
13
14 def _get_value_from_extra(self, quantity, at_date=None):
15 self.ensure_one()
16 accounting_data = super()._get_value_from_extra(quantity, at_date=at_date)
17 # Add landed costs value
18 lcs = self._get_landed_cost(at_date=at_date)
19 lcs = lcs.get(self)
20 if not lcs:
21 return accounting_data
22 lcs_desc = []
23 for lc in lcs:
24 accounting_data["value"] += lc.additional_landed_cost
25 landed_cost = lc.cost_id
26 value = lc.additional_landed_cost
27 vendor_bill = landed_cost.vendor_bill_id
28 if vendor_bill:
29 desc = self.env._("+ %(value)s from %(vendor_bill)s (Landed Cost: %(landed_cost)s)",
30 value=self.company_currency_id.format(value), vendor_bill=vendor_bill.display_name, landed_cost=landed_cost.display_name)
31 else:
32 desc = self.env._("+ %(value)s (Landed Cost: %(landed_cost)s)",
33 value=self.company_currency_id.format(value), landed_cost=landed_cost.display_name)
34 lcs_desc.append(desc)
35 description = self.env._("Additional landed costs:\n%(landed_cost)s", landed_cost='\n'.join(lcs_desc))
36 if not accounting_data['description']:
37 accounting_data['description'] = description
38 else:
39 accounting_data['description'] += '\n' + description
40 return accounting_data