diff --git a/sale_customer_rank/__init__.py b/sale_customer_rank/__init__.py new file mode 100644 index 00000000000..b689086b7e3 --- /dev/null +++ b/sale_customer_rank/__init__.py @@ -0,0 +1,11 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models +from odoo import api, SUPERUSER_ID + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + partners = env["sale.order"].search([]).mapped("partner_id") + partners |= partners.mapped("commercial_partner_id") + partners._increase_rank("customer_rank") diff --git a/sale_customer_rank/__manifest__.py b/sale_customer_rank/__manifest__.py new file mode 100644 index 00000000000..21ed6952de6 --- /dev/null +++ b/sale_customer_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": "Sale Customer Rank", + "summary": "Update Customer Rank when creating a Sale Order", + "version": "13.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/partner-contact", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["sale"], + "data": [], + "post_init_hook": "post_init_hook", +} diff --git a/sale_customer_rank/models/__init__.py b/sale_customer_rank/models/__init__.py new file mode 100644 index 00000000000..b1ad204bdec --- /dev/null +++ b/sale_customer_rank/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import sale_order diff --git a/sale_customer_rank/models/sale_order.py b/sale_customer_rank/models/sale_order.py new file mode 100644 index 00000000000..7e9bf434a5f --- /dev/null +++ b/sale_customer_rank/models/sale_order.py @@ -0,0 +1,16 @@ +# Copyright 2021 ForgeFlow, S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.model + def create(self, vals): + res = super().create(vals) + if res: + partners = res.partner_id | res.partner_id.commercial_partner_id + partners._increase_rank("customer_rank") + return res diff --git a/sale_customer_rank/readme/CONTRIBUTORS.rst b/sale_customer_rank/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..37c5e66cfdd --- /dev/null +++ b/sale_customer_rank/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Miquel Raïch diff --git a/sale_customer_rank/readme/DESCRIPTION.rst b/sale_customer_rank/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..64958765f02 --- /dev/null +++ b/sale_customer_rank/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module updates customer_rank for partners when creating sale orders. diff --git a/sale_customer_rank/static/description/icon.png b/sale_customer_rank/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_customer_rank/static/description/icon.png differ