Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] company_default_partner_pricelist #1946

Open
wants to merge 12 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions company_default_partner_pricelist/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=================================
Company Default Partner Pricelist
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0f3bf1f33bb78d925a93f4930fc19d1354f4c7d93aa48a1450d46f1f4e181bd1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/16.0/company_default_partner_pricelist
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-company_default_partner_pricelist
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

If the pricelist of a partner is not explicitly set, Odoo will try by default
to find a valid pricelist based on the country of the partner.

This module allows assigning a default pricelist for each company in the system
to use as the default pricelist for partners.

**Table of contents**

.. contents::
:local:

Configuration
=============

To Configure the default company Pricelist:

- Go to **General Settings** -> **Companies**
- Press the **"Update Info"** button
- On the Company form view, please select a pricelist for a company in the **"Default Account Pricelist"** field

Usage
=====

To use this module simply assign a default pricelist to the companies for
which you want to have a specific default value.

If no default pricelist is assigned, the standard logic will apply.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20company_default_partner_pricelist%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ForgeFlow

Contributors
~~~~~~~~~~~~

* `ForgeFlow <https://www.forgeflow.com>`

* Jordi Masvidal

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/16.0/company_default_partner_pricelist>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions company_default_partner_pricelist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions company_default_partner_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Company Default Partner Pricelist",
"summary": """
Define default partner pricelist per company.
""",
"version": "16.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"category": "Partner Management",
"depends": ["product"],
"data": ["views/res_company_views.xml"],
"installable": True,
"license": "LGPL-3",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * company_default_partner_pricelist
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: company_default_partner_pricelist
#: model:ir.model,name:company_default_partner_pricelist.model_res_company
msgid "Companies"
msgstr ""

#. module: company_default_partner_pricelist
#: model:ir.model.fields,field_description:company_default_partner_pricelist.field_res_company__default_property_product_pricelist
msgid "Default Account Pricelist"
msgstr ""

#. module: company_default_partner_pricelist
#: 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 ""
1 change: 1 addition & 0 deletions company_default_partner_pricelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_company
59 changes: 59 additions & 0 deletions company_default_partner_pricelist/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

default_property_product_pricelist = fields.Many2one(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default_property_product_pricelist = fields.Many2one(
default_property_product_pricelist_id = fields.Many2one(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should have a subfix as _id for many2one

"product.pricelist",
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"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ir_property = self.env["ir.property"]
IrProperty = self.env["ir.property"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe set it with sudo() here too since you use sudo for all the following calls

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()

Check warning on line 51 in company_default_partner_pricelist/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

company_default_partner_pricelist/models/res_company.py#L51

Added line #L51 was not covered by tests
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
5 changes: 5 additions & 0 deletions company_default_partner_pricelist/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To Configure the default company Pricelist:

- Go to **General Settings** -> **Companies**
- Press the **"Update Info"** button
- On the Company form view, please select a pricelist for a company in the **"Default Account Pricelist"** field
3 changes: 3 additions & 0 deletions company_default_partner_pricelist/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `ForgeFlow <https://www.forgeflow.com>`

* Jordi Masvidal
5 changes: 5 additions & 0 deletions company_default_partner_pricelist/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
If the pricelist of a partner is not explicitly set, Odoo will try by default
to find a valid pricelist based on the country of the partner.

This module allows assigning a default pricelist for each company in the system
to use as the default pricelist for partners.
4 changes: 4 additions & 0 deletions company_default_partner_pricelist/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To use this module simply assign a default pricelist to the companies for
which you want to have a specific default value.

If no default pricelist is assigned, the standard logic will apply.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading