Skip to content
Snippets Groups Projects
Commit 9be69008 authored by William Henrotin's avatar William Henrotin Committed by Arnold Moyaux
Browse files

[FIX] stock: remove dynamic domain on return wizard

parent dd76e2df
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
'views/stock_move_views.xml',
'views/stock_picking_views.xml',
'views/supplier_info_views.xml',
'wizard/stock_picking_return_views.xml',
],
'demo': [
'data/mrp_subcontracting_demo.xml',
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
from odoo.osv.expression import OR
from odoo import api, models, fields
class ReturnPicking(models.TransientModel):
_inherit = 'stock.return.picking'
subcontract_location_id = fields.Many2one('stock.location', compute='_compute_subcontract_location_id')
@api.depends('picking_id')
def _compute_subcontract_location_id(self):
for record in self:
record.subcontract_location_id = record.picking_id.partner_id.with_company(
record.picking_id.company_id
).property_stock_subcontractor
@api.onchange('picking_id')
def _onchange_picking_id(self):
res = super(ReturnPicking, self)._onchange_picking_id()
if not any(self.product_return_moves.filtered(lambda r: r.quantity > 0).move_id.mapped('is_subcontract')):
return res
subcontract_location = self.picking_id.partner_id.with_company(self.picking_id.company_id).property_stock_subcontractor
self.location_id = subcontract_location.id
domain_location = OR([
['|', ('id', '=', self.original_location_id.id), ('return_location', '=', True)],
[('id', '=', subcontract_location.id)]
])
if not res:
res = {'domain': {'location_id': domain_location}}
else:
res['domain'] = {'location_id': domain_location}
if any(self.product_return_moves.filtered(lambda r: r.quantity > 0).move_id.mapped('is_subcontract')):
self.location_id = self.picking_id.partner_id.with_company(self.picking_id.company_id).property_stock_subcontractor
return res
def _prepare_move_default_values(self, return_line, new_picking):
......
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_stock_return_picking_form_subcontracting" model="ir.ui.view">
<field name="name">Return lines</field>
<field name="model">stock.return.picking</field>
<field name="inherit_id" ref="stock.view_stock_return_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='location_id']" position="before">
<field name="subcontract_location_id" invisible="1"/>
<field name="original_location_id" invisible="1"/>
</xpath>
<xpath expr="//field[@name='location_id']" position="attributes">
<attribute name="domain">
['|', '|', ('id', '=', original_location_id), ('return_location', '=', True), ('id', '=', subcontract_location_id)]
</attribute>
</xpath>
</field>
</record>
</odoo>
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