Skip to content
Snippets Groups Projects
Commit 50cbaef2 authored by Simon Lejeune's avatar Simon Lejeune
Browse files

[REF] stock_landed_costs: domain on transfers


The previous domain was too naive: a receipt is not always valued
(inter-warehouse transfer) and even a receipt that should be valued
isn't always (receive goods you do not own, change your config from
manual to automated and then apply the lc on an old receipt, etc.)

Enforce a domain making sure the transfer is valued.

related opw-2165697
task-2169844

closes odoo/odoo#43410

X-original-commit: c6aa61b2
Signed-off-by: default avatarSimon Lejeune (sle) <sle@openerp.com>
parent 218e1cad
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,7 @@ class LandedCost(models.Model):
picking_ids = fields.Many2many(
'stock.picking', string='Transfers',
copy=False, states={'done': [('readonly', True)]})
allowed_picking_ids = fields.Many2many('stock.picking', compute='_compute_allowed_picking_ids')
cost_lines = fields.One2many(
'stock.landed.cost.lines', 'cost_id', 'Cost Lines',
copy=True, states={'done': [('readonly', True)]})
......@@ -79,6 +80,18 @@ class LandedCost(models.Model):
for cost in self:
cost.amount_total = sum(line.price_unit for line in cost.cost_lines)
@api.depends('company_id')
def _compute_allowed_picking_ids(self):
self.env.cr.execute("""SELECT sm.picking_id, sm.company_id
FROM stock_move AS sm
INNER JOIN stock_valuation_layer AS svl ON svl.stock_move_id = sm.id
WHERE sm.picking_id IS NOT NULL""")
valued_picking_ids_per_company = defaultdict(list)
for res in self.env.cr.fetchall():
valued_picking_ids_per_company[res[1]].append(res[0])
for cost in self:
cost.allowed_picking_ids = valued_picking_ids_per_company[cost.company_id.id]
@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
......
......@@ -29,7 +29,8 @@
<group>
<group>
<field name="date"/>
<field name="picking_ids" widget="many2many_tags" options="{'no_create_edit': True}" domain="[('state', '=', 'done'), ('picking_type_code', '!=', 'internal')]"/>
<field name="allowed_picking_ids" invisible="1"/>
<field name="picking_ids" widget="many2many_tags" options="{'no_create_edit': True}" domain="[('id', 'in', allowed_picking_ids)]"/>
</group>
<group>
<label for="account_journal_id" string="Journal"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment