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 [UPD] Update mrp_subcontracting_partner_management.pot [UPD] README.rst mrp_subcontracting_partner_management 14.0.1.0.1
This commit is contained in:
@@ -55,6 +55,12 @@ Usage
|
||||
Changelog
|
||||
=========
|
||||
|
||||
14.0.1.0.1
|
||||
~~~~~~~~~~
|
||||
|
||||
**Bugfixes**
|
||||
- Fixed duplicate rules when creating a subcontractor partner
|
||||
|
||||
14.0.1.0.0
|
||||
~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Subcontracting Partner Management",
|
||||
"version": "14.0.1.0.0",
|
||||
"version": "14.0.1.0.1",
|
||||
"summary": "Subcontracting Partner Management",
|
||||
"author": "Ooops404, Cetmix, Odoo Community Association (OCA)",
|
||||
"license": "LGPL-3",
|
||||
@@ -11,6 +11,7 @@
|
||||
"demo": [],
|
||||
"data": [
|
||||
"views/res_partner.xml",
|
||||
"views/stock_picking_type.xml",
|
||||
],
|
||||
"qweb": [],
|
||||
"installable": True,
|
||||
|
||||
@@ -20,16 +20,24 @@ msgstr ""
|
||||
|
||||
#. module: mrp_subcontracting_partner_management
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_partner__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_stock_picking_type__display_name
|
||||
msgid "Display Name"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_subcontracting_partner_management
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_partner__id
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_stock_picking_type__id
|
||||
msgid "ID"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_subcontracting_partner_management
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_stock_picking_type__is_subcontractor
|
||||
msgid "Is Subcontractor"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_subcontracting_partner_management
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_partner____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_stock_picking_type____last_update
|
||||
msgid "Last Modified on"
|
||||
msgstr ""
|
||||
|
||||
@@ -51,6 +59,11 @@ msgstr ""
|
||||
msgid "Partner Resupply Rule"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_subcontracting_partner_management
|
||||
#: model:ir.model,name:mrp_subcontracting_partner_management.model_stock_picking_type
|
||||
msgid "Picking Type"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_subcontracting_partner_management
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_partner__subcontracted_created_location_id
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_users__subcontracted_created_location_id
|
||||
@@ -61,5 +74,6 @@ msgstr ""
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_partner__is_subcontractor_partner
|
||||
#: model:ir.model.fields,field_description:mrp_subcontracting_partner_management.field_res_users__is_subcontractor_partner
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_subcontracting_partner_management.view_partner_form_inherit_subcontractor
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_subcontracting_partner_management.view_pickingtype_filter
|
||||
msgid "Subcontractor"
|
||||
msgstr ""
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from . import res_partner
|
||||
from . import stock_picking_type
|
||||
|
||||
@@ -5,10 +5,20 @@ class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
is_subcontractor_partner = fields.Boolean(string="Subcontractor")
|
||||
subcontracted_created_location_id = fields.Many2one("stock.location")
|
||||
partner_picking_type_id = fields.Many2one("stock.picking.type")
|
||||
partner_buy_rule_id = fields.Many2one("stock.rule")
|
||||
partner_resupply_rule_id = fields.Many2one("stock.rule")
|
||||
subcontracted_created_location_id = fields.Many2one(
|
||||
copy=False, comodel_name="stock.location"
|
||||
)
|
||||
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):
|
||||
self.ensure_one()
|
||||
@@ -23,7 +33,7 @@ class ResPartner(models.Model):
|
||||
|
||||
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:
|
||||
record._set_subcontracting_values_active(False)
|
||||
@@ -47,12 +57,19 @@ class ResPartner(models.Model):
|
||||
partner._create_subcontractor_entities()
|
||||
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):
|
||||
"""Creating Subcontracting Location starts here"""
|
||||
|
||||
name = "Subcontractor {}".format(self.name)
|
||||
location_vals = {
|
||||
"name": name,
|
||||
"name": self._compose_entity_name(),
|
||||
"usage": "internal",
|
||||
"location_id": parent_location or False,
|
||||
"company_id": company.id,
|
||||
@@ -65,8 +82,8 @@ class ResPartner(models.Model):
|
||||
|
||||
def _create_subcontracted_operation_type(self, warehouse, location):
|
||||
"""Creating Operation Type for Subcontracting"""
|
||||
first_name = self.name.split(" ")[0] or ""
|
||||
operation_type_name = "Subcontractor {} {}".format(str(first_name), " IN")
|
||||
name = self._compose_entity_name()
|
||||
operation_type_name = "{}: {}".format(name, " IN")
|
||||
sequence_code = ""
|
||||
for code in list(filter(None, operation_type_name.split(" "))):
|
||||
sequence_code += code[0]
|
||||
@@ -76,6 +93,7 @@ class ResPartner(models.Model):
|
||||
"name": operation_type_name,
|
||||
"code": "incoming",
|
||||
"sequence_code": sequence_code,
|
||||
"is_subcontractor": True,
|
||||
}
|
||||
if warehouse:
|
||||
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):
|
||||
"""Creating Route Rule for Subcontracting starts here"""
|
||||
first_name = self.name.split(" ")[0] or ""
|
||||
buy_route = self.env.ref(
|
||||
"purchase_stock.route_warehouse0_buy", raise_if_not_found=False
|
||||
)
|
||||
rule_vals = {
|
||||
"name": "Subcontractor {}".format(first_name),
|
||||
"action": "buy",
|
||||
}
|
||||
rule = self.partner_buy_rule_id
|
||||
if operation_type_rec:
|
||||
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)
|
||||
if not rule:
|
||||
buy_route = self.env.ref(
|
||||
"purchase_stock.route_warehouse0_buy", raise_if_not_found=False
|
||||
)
|
||||
rule = self.env["stock.rule"].create(
|
||||
{
|
||||
"name": self._compose_entity_name(),
|
||||
"action": "buy",
|
||||
"picking_type_id": operation_type_rec.id,
|
||||
"location_id": location.id,
|
||||
"route_id": buy_route.id,
|
||||
}
|
||||
)
|
||||
self.partner_buy_rule_id = rule
|
||||
return rule
|
||||
|
||||
def _create_subcontracted_resupply_rule(self, location):
|
||||
"""# Creating Route Rule for Subcontracting resupply on order starts here"""
|
||||
first_name = self.name.split(" ")[0] or ""
|
||||
resupply_on_order_route = self.env.ref(
|
||||
"mrp_subcontracting.route_resupply_subcontractor_mto",
|
||||
raise_if_not_found=False,
|
||||
@@ -118,44 +133,25 @@ class ResPartner(models.Model):
|
||||
production = self.env["ir.property"]._get(
|
||||
"property_stock_production", "product.template"
|
||||
)
|
||||
resupply_rule_vals = {
|
||||
"name": "Subcontractor {}".format(first_name),
|
||||
"action": "pull",
|
||||
"partner_address_id": self._origin.id,
|
||||
}
|
||||
pull_rule = self.partner_resupply_rule_id
|
||||
if delivery_type:
|
||||
resupply_rule_vals.update(
|
||||
if not pull_rule:
|
||||
pull_rule = self.env["stock.rule"].create(
|
||||
{
|
||||
"name": self._compose_entity_name(),
|
||||
"action": "pull",
|
||||
"partner_address_id": self._origin.id,
|
||||
"picking_type_id": delivery_type.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(
|
||||
{
|
||||
"location_id": production.id,
|
||||
"location_src_id": location.id,
|
||||
"route_id": resupply_on_order_route.id,
|
||||
"procure_method": "mts_else_mto",
|
||||
}
|
||||
)
|
||||
|
||||
if not pull_rule and resupply_rule_vals:
|
||||
pull_rule = self.env["stock.rule"].create(resupply_rule_vals)
|
||||
self.partner_resupply_rule_id = pull_rule
|
||||
return pull_rule
|
||||
|
||||
def _create_subcontractor_entities(self):
|
||||
"""
|
||||
Create entities for the subcontractor
|
||||
"""Create entities for the subcontractor
|
||||
- Stock location
|
||||
- Stock operation type
|
||||
- "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
|
||||
~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -379,29 +379,30 @@ ul.auto-toc {
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#configuration" id="id2">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="id3">Usage</a></li>
|
||||
<li><a class="reference internal" href="#changelog" id="id4">Changelog</a><ul>
|
||||
<li><a class="reference internal" href="#id1" id="id5">14.0.1.0.0</a></li>
|
||||
<li><a class="reference internal" href="#configuration" id="id3">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="id4">Usage</a></li>
|
||||
<li><a class="reference internal" href="#changelog" id="id5">Changelog</a><ul>
|
||||
<li><a class="reference internal" href="#id1" id="id6">14.0.1.0.1</a></li>
|
||||
<li><a class="reference internal" href="#id2" id="id7">14.0.1.0.0</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id6">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id7">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id8">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id9">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id10">Maintainers</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id8">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id9">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id10">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id11">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id12">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="configuration">
|
||||
<h1><a class="toc-backref" href="#id2">Configuration</a></h1>
|
||||
<h1><a class="toc-backref" href="#id3">Configuration</a></h1>
|
||||
<ul class="simple">
|
||||
<li>No configuration is required</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#id3">Usage</a></h1>
|
||||
<h1><a class="toc-backref" href="#id4">Usage</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Select a partner of type “Company”</li>
|
||||
<li>Enable the “Subcontractor” checkbox</li>
|
||||
@@ -410,16 +411,21 @@ ul.auto-toc {
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="changelog">
|
||||
<h1><a class="toc-backref" href="#id4">Changelog</a></h1>
|
||||
<h1><a class="toc-backref" href="#id5">Changelog</a></h1>
|
||||
<div class="section" id="id1">
|
||||
<h2><a class="toc-backref" href="#id5">14.0.1.0.0</a></h2>
|
||||
<h2><a class="toc-backref" href="#id6">14.0.1.0.1</a></h2>
|
||||
<p><strong>Bugfixes</strong>
|
||||
- Fixed duplicate rules when creating a subcontractor partner</p>
|
||||
</div>
|
||||
<div class="section" id="id2">
|
||||
<h2><a class="toc-backref" href="#id7">14.0.1.0.0</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Initial release</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id6">Bug Tracker</a></h1>
|
||||
<h1><a class="toc-backref" href="#id8">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
@@ -427,23 +433,23 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id7">Credits</a></h1>
|
||||
<h1><a class="toc-backref" href="#id9">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id8">Authors</a></h2>
|
||||
<h2><a class="toc-backref" href="#id10">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Ooops404</li>
|
||||
<li>Cetmix</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id9">Contributors</a></h2>
|
||||
<h2><a class="toc-backref" href="#id11">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Ooops404 <<a class="reference external" href="https://www.ooops404.com/">https://www.ooops404.com/</a>></li>
|
||||
<li>Cetmix <<a class="reference external" href="https://cetmix.com/">https://cetmix.com/</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id10">Maintainers</a></h2>
|
||||
<h2><a class="toc-backref" href="#id12">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
|
||||
@@ -168,3 +168,16 @@ class TestSubcontractedPartner(common.SavepointCase):
|
||||
self.assertFalse(
|
||||
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