Browse Source

[ADD] partner_manual_rank

14.0
mreficent 4 years ago
committed by Francesco Apruzzese
parent
commit
5dcf341478
  1. 31
      partner_manual_rank/__init__.py
  2. 16
      partner_manual_rank/__manifest__.py
  3. 3
      partner_manual_rank/models/__init__.py
  4. 49
      partner_manual_rank/models/res_partner.py
  5. 1
      partner_manual_rank/readme/CONTRIBUTORS.rst
  6. 2
      partner_manual_rank/readme/DESCRIPTION.rst
  7. BIN
      partner_manual_rank/static/description/icon.png
  8. 35
      partner_manual_rank/views/res_partner.xml

31
partner_manual_rank/__init__.py

@ -0,0 +1,31 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
from odoo.tools.sql import column_exists
def pre_init_hook(cr):
if not column_exists(cr, "res_partner", "is_customer"):
cr.execute(
"""
ALTER TABLE res_partner
ADD COLUMN is_customer boolean""",
)
cr.execute(
"""
UPDATE res_partner
SET is_customer = customer_rank::boolean
"""
)
if not column_exists(cr, "res_partner", "is_supplier"):
cr.execute(
"""
ALTER TABLE res_partner
ADD COLUMN is_supplier boolean""",
)
cr.execute(
"""
UPDATE res_partner
SET is_supplier = supplier_rank::boolean
"""
)

16
partner_manual_rank/__manifest__.py

@ -0,0 +1,16 @@
# Copyright 2021 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Partner Manual Rank",
"summary": "Be able to manually flag partners as customer or supplier.",
"version": "13.0.1.0.0",
"category": "Partner Management",
"website": "https://github.com/OCA/partner-contact",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["account"],
"data": ["views/res_partner.xml"],
"pre_init_hook": "pre_init_hook",
}

3
partner_manual_rank/models/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import res_partner

49
partner_manual_rank/models/res_partner.py

@ -0,0 +1,49 @@
# Copyright 2021 ForgeFlow, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo 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

1
partner_manual_rank/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Miquel Raïch <miquel.raich@forgeflow.com>

2
partner_manual_rank/readme/DESCRIPTION.rst

@ -0,0 +1,2 @@
This module adds the ability to manually flag partners as customer or supplier
from the partner form view.

BIN
partner_manual_rank/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

35
partner_manual_rank/views/res_partner.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">partner_manual_rank.view_partner_filter</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="model">res.partner</field>
<field type="xml" name="arch">
<field name="parent_id" position="after">
<field name="is_customer" />
<field name="is_supplier" />
</field>
</field>
</record>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">partner_manual_rank.view_partner_form</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="model">res.partner</field>
<field type="xml" name="arch">
<xpath expr="//field[@name='child_ids']/kanban/templates" position="before">
<field name="is_customer" />
<field name="is_supplier" />
</xpath>
<xpath expr="//field[@name='child_ids']/form/sheet" position="inside">
<field name="is_customer" invisible="1" />
<field name="is_supplier" invisible="1" />
</xpath>
<xpath expr="//group[@name='sale']/field[1]" position="before">
<field name="is_customer" />
</xpath>
<xpath expr="//group[@name='purchase']/field[1]" position="before">
<field name="is_supplier" />
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save