Skip to content

Commit

Permalink
Merge pull request #1157 from OCA/13.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/partner-contact (13.0)
  • Loading branch information
bt-admin authored Feb 23, 2024
2 parents c97cda8 + 6e3ddfc commit 48961f3
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ addon | version | maintainers | summary
[base_location_nuts](base_location_nuts/) | 13.0.1.0.2 | | NUTS Regions
[base_partner_sequence](base_partner_sequence/) | 13.0.1.0.2 | | Sets customer's code from a sequence
[base_vat_sanitized](base_vat_sanitized/) | 13.0.1.0.0 | | Adds field sanitized_vat on partners
[company_default_partner_pricelist](company_default_partner_pricelist/) | 13.0.1.0.0 | | Define default partner pricelist per company.
[company_default_partner_pricelist](company_default_partner_pricelist/) | 13.0.1.0.1 | | Define default partner pricelist per company.
[partner_address_street3](partner_address_street3/) | 13.0.1.0.0 | | Add a third address line on partners
[partner_address_two_lines](partner_address_two_lines/) | 13.0.1.0.2 | | The company and the partner name are on two different lines
[partner_affiliate](partner_affiliate/) | 13.0.1.1.0 | | Partner Affiliates
Expand Down
2 changes: 1 addition & 1 deletion company_default_partner_pricelist/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Company Default Partner Pricelist
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b33818bef59cd07049f797399f1bea08bd178af0ab9db0f5239018e60a15b437
!! source digest: sha256:0f3bf1f33bb78d925a93f4930fc19d1354f4c7d93aa48a1450d46f1f4e181bd1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion company_default_partner_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"summary": """
Define default partner pricelist per company.
""",
"version": "13.0.1.0.0",
"version": "13.0.1.0.1",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"category": "Partner Management",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,3 @@ msgstr ""
#: model:ir.model.fields,help:company_default_partner_pricelist.field_res_company__default_property_product_pricelist
msgid "Default pricelist for this company for new partners."
msgstr ""

#. module: company_default_partner_pricelist
#: model:ir.model,name:company_default_partner_pricelist.model_product_pricelist
msgid "Pricelist"
msgstr ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
company = env["res.company"]
ir_property = env["ir.property"]
field = env["ir.model.fields"]._get("res.partner", "property_product_pricelist")
for record in company.search([]):
company_default_pricelist = record.default_property_product_pricelist
if not company_default_pricelist:
continue
ppty = ir_property.search(
[
("name", "=", "property_product_pricelist"),
("company_id", "=", record.id),
("fields_id", "=", field.id),
("res_id", "=", False),
("value_reference", "!=", False),
],
limit=1,
)
if ppty:
res = ppty.value_reference.split(",")
res_id = int(res[1])
if res_id != company_default_pricelist.id:
ppty.sudo().write(
{
"value_reference": "product.pricelist,%s"
% company_default_pricelist.id
}
)
else:
ir_property.sudo().create(
{
"name": "property_product_pricelist",
"value_reference": "product.pricelist,%s"
% company_default_pricelist.id,
"fields_id": field.id,
"company_id": record.id,
}
)
1 change: 0 additions & 1 deletion company_default_partner_pricelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import product_pricelist
from . import res_company
14 changes: 0 additions & 14 deletions company_default_partner_pricelist/models/product_pricelist.py

This file was deleted.

46 changes: 46 additions & 0 deletions company_default_partner_pricelist/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,49 @@ class ResCompany(models.Model):
string="Default Account Pricelist",
help="Default pricelist for this company for new partners.",
)

def _update_partner_pricelist_generic_property(self):
self.ensure_one()
default_property_pp = self.default_property_product_pricelist
ir_property = self.env["ir.property"]
field = self.env["ir.model.fields"]._get(
"res.partner", "property_product_pricelist"
)
ppty = ir_property.sudo().search(
[
("name", "=", "property_product_pricelist"),
("company_id", "=", self.id),
("fields_id", "=", field.id),
("res_id", "=", False),
],
limit=1,
)
if ppty:
if not default_property_pp:
ppty.sudo().unlink()
else:
ppty.sudo().write(
{"value_reference": "product.pricelist,%s" % default_property_pp.id}
)
elif default_property_pp:
ir_property.sudo().create(
{
"name": "property_product_pricelist",
"value_reference": "product.pricelist,%s" % default_property_pp.id,
"fields_id": field.id,
"company_id": self.id,
}
)

def create(self, vals):
res = super(ResCompany, self).create(vals)
if "default_property_product_pricelist" in vals:
res._update_partner_pricelist_generic_property()
return res

def write(self, vals):
res = super(ResCompany, self).write(vals)
if "default_property_product_pricelist" in vals:
for rec in self:
rec._update_partner_pricelist_generic_property()
return res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -367,7 +366,7 @@ <h1 class="title">Company Default Partner Pricelist</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b33818bef59cd07049f797399f1bea08bd178af0ab9db0f5239018e60a15b437
!! source digest: sha256:0f3bf1f33bb78d925a93f4930fc19d1354f4c7d93aa48a1450d46f1f4e181bd1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/partner-contact/tree/13.0/company_default_partner_pricelist"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-company_default_partner_pricelist"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&amp;target_branch=13.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>If the pricelist of a partner is not explicitly set, Odoo will try by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def setUp(self):
self.pricelist_2 = self.env["product.pricelist"].create(
{"name": "Test pricelist 2"}
)
self.pricelist_3 = self.env["product.pricelist"].create(
{"name": "Test pricelist 3"}
)
self.partner = self.env["res.partner"].create({"name": "Test customer"})

def test_company_default_partner_pricelist(self):
Expand All @@ -25,6 +28,15 @@ def test_company_default_partner_pricelist(self):
self.env.company.default_property_product_pricelist = self.pricelist_2
self.partner.invalidate_cache()
self.assertEqual(self.partner.property_product_pricelist, self.pricelist_2)

self.env.company.default_property_product_pricelist = self.pricelist_3
self.partner.invalidate_cache()
self.assertEqual(self.partner.property_product_pricelist, self.pricelist_3)

self.env.company.default_property_product_pricelist = False
self.partner.invalidate_cache()
self.assertEqual(self.partner.property_product_pricelist, self.base_pricelist)

# Finally, when modified explicitly, the pricelist is the one
# set by the user
self.partner.property_product_pricelist = self.pricelist_1
Expand Down

0 comments on commit 48961f3

Please sign in to comment.