mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[FIX] set correct values when duplicating partner
[IMP] res.partner: Use function to compose entiry name stock.picking.type: Boolean field "is_subcontractor" for UI filters
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"demo": [],
|
"demo": [],
|
||||||
"data": [
|
"data": [
|
||||||
"views/res_partner.xml",
|
"views/res_partner.xml",
|
||||||
|
"views/stock_picking_type.xml",
|
||||||
],
|
],
|
||||||
"qweb": [],
|
"qweb": [],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from . import res_partner
|
from . import res_partner
|
||||||
|
from . import stock_picking_type
|
||||||
|
|||||||
@@ -5,10 +5,20 @@ class ResPartner(models.Model):
|
|||||||
_inherit = "res.partner"
|
_inherit = "res.partner"
|
||||||
|
|
||||||
is_subcontractor_partner = fields.Boolean(string="Subcontractor")
|
is_subcontractor_partner = fields.Boolean(string="Subcontractor")
|
||||||
subcontracted_created_location_id = fields.Many2one("stock.location")
|
subcontracted_created_location_id = fields.Many2one(
|
||||||
partner_picking_type_id = fields.Many2one("stock.picking.type")
|
copy=False, comodel_name="stock.location"
|
||||||
partner_buy_rule_id = fields.Many2one("stock.rule")
|
)
|
||||||
partner_resupply_rule_id = fields.Many2one("stock.rule")
|
partner_picking_type_id = fields.Many2one(
|
||||||
|
copy=False, comodel_name="stock.picking.type"
|
||||||
|
)
|
||||||
|
partner_buy_rule_id = fields.Many2one(
|
||||||
|
copy=False,
|
||||||
|
comodel_name="stock.rule",
|
||||||
|
)
|
||||||
|
partner_resupply_rule_id = fields.Many2one(
|
||||||
|
copy=False,
|
||||||
|
comodel_name="stock.rule",
|
||||||
|
)
|
||||||
|
|
||||||
def _set_subcontracting_values_active(self, active):
|
def _set_subcontracting_values_active(self, active):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@@ -23,7 +33,7 @@ class ResPartner(models.Model):
|
|||||||
|
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
"""
|
"""
|
||||||
This Method is override to archive all subcotracting field
|
This Method is override to archive all subcontracting field
|
||||||
"""
|
"""
|
||||||
for record in self:
|
for record in self:
|
||||||
record._set_subcontracting_values_active(False)
|
record._set_subcontracting_values_active(False)
|
||||||
@@ -47,12 +57,19 @@ class ResPartner(models.Model):
|
|||||||
partner._create_subcontractor_entities()
|
partner._create_subcontractor_entities()
|
||||||
return partner
|
return partner
|
||||||
|
|
||||||
|
def _compose_entity_name(self):
|
||||||
|
"""Compose entity name.
|
||||||
|
Override this function to implement onw logic
|
||||||
|
Returns:
|
||||||
|
name (char) composed name
|
||||||
|
"""
|
||||||
|
return self.display_name
|
||||||
|
|
||||||
def _create_location(self, parent_location, company):
|
def _create_location(self, parent_location, company):
|
||||||
"""Creating Subcontracting Location starts here"""
|
"""Creating Subcontracting Location starts here"""
|
||||||
|
|
||||||
name = "Subcontractor {}".format(self.name)
|
|
||||||
location_vals = {
|
location_vals = {
|
||||||
"name": name,
|
"name": self._compose_entity_name(),
|
||||||
"usage": "internal",
|
"usage": "internal",
|
||||||
"location_id": parent_location or False,
|
"location_id": parent_location or False,
|
||||||
"company_id": company.id,
|
"company_id": company.id,
|
||||||
@@ -65,8 +82,8 @@ class ResPartner(models.Model):
|
|||||||
|
|
||||||
def _create_subcontracted_operation_type(self, warehouse, location):
|
def _create_subcontracted_operation_type(self, warehouse, location):
|
||||||
"""Creating Operation Type for Subcontracting"""
|
"""Creating Operation Type for Subcontracting"""
|
||||||
first_name = self.name.split(" ")[0] or ""
|
name = self._compose_entity_name()
|
||||||
operation_type_name = "Subcontractor {} {}".format(str(first_name), " IN")
|
operation_type_name = "{}: {}".format(name, " IN")
|
||||||
sequence_code = ""
|
sequence_code = ""
|
||||||
for code in list(filter(None, operation_type_name.split(" "))):
|
for code in list(filter(None, operation_type_name.split(" "))):
|
||||||
sequence_code += code[0]
|
sequence_code += code[0]
|
||||||
@@ -76,6 +93,7 @@ class ResPartner(models.Model):
|
|||||||
"name": operation_type_name,
|
"name": operation_type_name,
|
||||||
"code": "incoming",
|
"code": "incoming",
|
||||||
"sequence_code": sequence_code,
|
"sequence_code": sequence_code,
|
||||||
|
"is_subcontractor": True,
|
||||||
}
|
}
|
||||||
if warehouse:
|
if warehouse:
|
||||||
operation_type_vals.update({"warehouse_id": warehouse.id})
|
operation_type_vals.update({"warehouse_id": warehouse.id})
|
||||||
@@ -88,28 +106,25 @@ class ResPartner(models.Model):
|
|||||||
|
|
||||||
def _create_subcontracted_buy_rule(self, operation_type_rec, location):
|
def _create_subcontracted_buy_rule(self, operation_type_rec, location):
|
||||||
"""Creating Route Rule for Subcontracting starts here"""
|
"""Creating Route Rule for Subcontracting starts here"""
|
||||||
first_name = self.name.split(" ")[0] or ""
|
rule = self.partner_buy_rule_id
|
||||||
|
if not rule:
|
||||||
buy_route = self.env.ref(
|
buy_route = self.env.ref(
|
||||||
"purchase_stock.route_warehouse0_buy", raise_if_not_found=False
|
"purchase_stock.route_warehouse0_buy", raise_if_not_found=False
|
||||||
)
|
)
|
||||||
rule_vals = {
|
rule = self.env["stock.rule"].create(
|
||||||
"name": "Subcontractor {}".format(first_name),
|
{
|
||||||
|
"name": self._compose_entity_name(),
|
||||||
"action": "buy",
|
"action": "buy",
|
||||||
|
"picking_type_id": operation_type_rec.id,
|
||||||
|
"location_id": location.id,
|
||||||
|
"route_id": buy_route.id,
|
||||||
}
|
}
|
||||||
rule = self.partner_buy_rule_id
|
)
|
||||||
if operation_type_rec:
|
self.partner_buy_rule_id = rule
|
||||||
rule_vals.update({"picking_type_id": operation_type_rec.id})
|
|
||||||
if location:
|
|
||||||
rule_vals.update({"location_id": location.id})
|
|
||||||
if buy_route:
|
|
||||||
rule_vals.update({"route_id": buy_route.id})
|
|
||||||
if not rule and rule_vals:
|
|
||||||
rule = self.env["stock.rule"].create(rule_vals)
|
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
def _create_subcontracted_resupply_rule(self, location):
|
def _create_subcontracted_resupply_rule(self, location):
|
||||||
"""# Creating Route Rule for Subcontracting resupply on order starts here"""
|
"""# Creating Route Rule for Subcontracting resupply on order starts here"""
|
||||||
first_name = self.name.split(" ")[0] or ""
|
|
||||||
resupply_on_order_route = self.env.ref(
|
resupply_on_order_route = self.env.ref(
|
||||||
"mrp_subcontracting.route_resupply_subcontractor_mto",
|
"mrp_subcontracting.route_resupply_subcontractor_mto",
|
||||||
raise_if_not_found=False,
|
raise_if_not_found=False,
|
||||||
@@ -118,44 +133,25 @@ class ResPartner(models.Model):
|
|||||||
production = self.env["ir.property"]._get(
|
production = self.env["ir.property"]._get(
|
||||||
"property_stock_production", "product.template"
|
"property_stock_production", "product.template"
|
||||||
)
|
)
|
||||||
resupply_rule_vals = {
|
pull_rule = self.partner_resupply_rule_id
|
||||||
"name": "Subcontractor {}".format(first_name),
|
if not pull_rule:
|
||||||
|
pull_rule = self.env["stock.rule"].create(
|
||||||
|
{
|
||||||
|
"name": self._compose_entity_name(),
|
||||||
"action": "pull",
|
"action": "pull",
|
||||||
"partner_address_id": self._origin.id,
|
"partner_address_id": self._origin.id,
|
||||||
}
|
|
||||||
pull_rule = self.partner_resupply_rule_id
|
|
||||||
if delivery_type:
|
|
||||||
resupply_rule_vals.update(
|
|
||||||
{
|
|
||||||
"picking_type_id": delivery_type.id,
|
"picking_type_id": delivery_type.id,
|
||||||
}
|
"location_id": production.id,
|
||||||
)
|
"location_src_id": location.id,
|
||||||
if location:
|
|
||||||
resupply_rule_vals.update(
|
|
||||||
{
|
|
||||||
"location_id": location.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if production:
|
|
||||||
resupply_rule_vals.update(
|
|
||||||
{
|
|
||||||
"location_src_id": production.id,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if resupply_on_order_route:
|
|
||||||
resupply_rule_vals.update(
|
|
||||||
{
|
|
||||||
"route_id": resupply_on_order_route.id,
|
"route_id": resupply_on_order_route.id,
|
||||||
|
"procure_method": "mts_else_mto",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
self.partner_resupply_rule_id = pull_rule
|
||||||
if not pull_rule and resupply_rule_vals:
|
|
||||||
pull_rule = self.env["stock.rule"].create(resupply_rule_vals)
|
|
||||||
return pull_rule
|
return pull_rule
|
||||||
|
|
||||||
def _create_subcontractor_entities(self):
|
def _create_subcontractor_entities(self):
|
||||||
"""
|
"""Create entities for the subcontractor
|
||||||
Create entities for the subcontractor
|
|
||||||
- Stock location
|
- Stock location
|
||||||
- Stock operation type
|
- Stock operation type
|
||||||
- "Buy" stock rule
|
- "Buy" stock rule
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class StockPickingType(models.Model):
|
||||||
|
_inherit = "stock.picking.type"
|
||||||
|
|
||||||
|
is_subcontractor = fields.Boolean()
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
14.0.1.0.1
|
||||||
|
~~~~~~~~~~
|
||||||
|
|
||||||
|
**Bugfixes**
|
||||||
|
- Fixed duplicate rules when creating a subcontractor partner
|
||||||
|
|
||||||
14.0.1.0.0
|
14.0.1.0.0
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -168,3 +168,16 @@ class TestSubcontractedPartner(common.SavepointCase):
|
|||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
partner_resupply_rule.active, "Partner Resupply rule must be not active"
|
partner_resupply_rule.active, "Partner Resupply rule must be not active"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_check_countof_rules(self):
|
||||||
|
partner_id = self.partner_obj.create(
|
||||||
|
{
|
||||||
|
"name": "Test partner",
|
||||||
|
"is_company": True,
|
||||||
|
"is_subcontractor_partner": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
rules = self.env["stock.rule"].search(
|
||||||
|
[("name", "=", partner_id.partner_buy_rule_id.name)]
|
||||||
|
)
|
||||||
|
self.assertTrue(len(rules) == 2, "There are must be 2 subcontractor rules")
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<!-- Add filter for subcontracting operation types -->
|
||||||
|
<record id="view_pickingtype_filter" model="ir.ui.view">
|
||||||
|
<field name="name">stock.picking.type.filter.subcontractor</field>
|
||||||
|
<field name="model">stock.picking.type</field>
|
||||||
|
<field name="inherit_id" ref="stock.view_pickingtype_filter" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<filter name="inactive" position="after">
|
||||||
|
<filter
|
||||||
|
string="Subcontractor"
|
||||||
|
name="subocont"
|
||||||
|
domain="[('is_subcontractor','=',True)]"
|
||||||
|
/>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user