[IMP] mrp_subcontracting: hide is_subcontracting_location setting

The `is_subcontracting_location` setting is intended only for
complicated route/rule use cases therefore we make it visible
only in debug mode to prevent users from setting this value and
unintentionally creating a lot of new routes/rules unnecessary.

Additionally, it is expected that users who previously set these up
manually will not want their custom rules/routes changed but will still
need the existing behavior to continue, so we restore the previous check
for subcontracting locations set as sublocations of the primary company
subcontracting location.

Follow up to task: 2720393

Part-of: odoo/odoo#100219
This commit is contained in:
Tiffany Chang (tic)
2022-09-16 14:25:34 +02:00
parent 2507be3a78
commit 6d28c9c2e5
2 changed files with 4 additions and 2 deletions
@@ -6,7 +6,7 @@
<field name="inherit_id" ref="stock.view_location_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='return_location']" position='after'>
<field name="is_subcontracting_location" attrs="{'invisible': [('usage', '!=', 'internal')]}" readonly="context.get('default_is_subcontracting_location', False)"/>
<field name="is_subcontracting_location" groups="base.group_no_one" attrs="{'invisible': [('usage', '!=', 'internal')]}" readonly="context.get('default_is_subcontracting_location', False)"/>
</xpath>
</field>
</record>
@@ -8,7 +8,9 @@ class StockRule(models.Model):
_inherit = 'stock.rule'
def _prepare_purchase_order(self, company_id, origins, values):
if 'partner_id' not in values[0] and self.location_dest_id.is_subcontracting_location:
if 'partner_id' not in values[0] \
and (company_id.subcontracting_location_id.parent_path in self.location_dest_id.parent_path
or self.location_dest_id.is_subcontracting_location):
values[0]['partner_id'] = values[0]['group_id'].partner_id.id
return super()._prepare_purchase_order(company_id, origins, values)