partner-contact/partner_manual_rank/models/res_partner.py

50 lines
1.5 KiB
Python
Raw Normal View History

2021-08-01 02:13:14 +00:00
# Copyright 2021 ForgeFlow, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from flectra import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
is_customer = fields.Boolean(
compute="_compute_is_customer",
inverse="_inverse_is_customer",
store=True,
readonly=False,
string="Is a Customer",
)
is_supplier = fields.Boolean(
compute="_compute_is_supplier",
inverse="_inverse_is_supplier",
store=True,
readonly=False,
string="Is a Supplier",
)
@api.depends("customer_rank")
def _compute_is_customer(self):
for partner in self:
partner.is_customer = bool(partner.customer_rank)
@api.depends("supplier_rank")
def _compute_is_supplier(self):
for partner in self:
partner.is_supplier = bool(partner.supplier_rank)
def _inverse_is_customer(self):
for partner in self:
partners = partner | partner.commercial_partner_id
if partner.is_customer:
partners._increase_rank("customer_rank")
else:
partners.customer_rank = 0
def _inverse_is_supplier(self):
for partner in self:
partners = partner | partner.commercial_partner_id
if partner.is_supplier:
partners._increase_rank("supplier_rank")
else:
partners.supplier_rank = 0