Skip to content

Commit

Permalink
[ADD] sale_customer_rank
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow authored and amarcosg committed Jun 6, 2023
1 parent a4fee63 commit 0b9c6ee
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sale_customer_rank/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
16 changes: 16 additions & 0 deletions sale_customer_rank/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
3 changes: 3 additions & 0 deletions sale_customer_rank/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import sale_order
16 changes: 16 additions & 0 deletions sale_customer_rank/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions sale_customer_rank/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Miquel Raïch <[email protected]>
1 change: 1 addition & 0 deletions sale_customer_rank/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module updates customer_rank for partners when creating sale orders.
Binary file added sale_customer_rank/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0b9c6ee

Please sign in to comment.