Skip to content

Commit

Permalink
[IMP]sale_quotation_number: Boolean to determine whether quotation se…
Browse files Browse the repository at this point in the history
…quence has been used
  • Loading branch information
manuelregidor authored and Tisho99 committed Jan 14, 2025
1 parent 213271c commit 94e7bba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sale_quotation_number/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "Sale Quotation Numeration",
"summary": "Different sequence for sale quotations",
"version": "17.0.1.1.0",
"version": "17.0.1.1.1",
"category": "Sales Management",
"website": "https://github.com/OCA/sale-workflow",
"author": "Elico Corp, "
Expand Down
20 changes: 20 additions & 0 deletions sale_quotation_number/migrations/17.0.1.1.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Manuel Regidor <[email protected]> (Sygel)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

import odoo


def migrate(cr, version):
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
sequence = env["ir.sequence"].search([("code", "=", "sale.quotation")], limit=1)
orders = (
env["sale.order"]
.search(
[
("state", "in", ["draft", "sent"]),
("company_id.keep_name_so", "=", False),
]
)
.filtered(lambda a: a.name[: len(sequence.prefix)] == sequence.prefix)
)
orders.write({"quotation_seq_used": True})
25 changes: 15 additions & 10 deletions sale_quotation_number/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
# © 2020 Manuel Regidor <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import api, models
from odoo import api, fields, models


class SaleOrder(models.Model):
_inherit = "sale.order"

quotation_seq_used = fields.Boolean(
string="Quotation Sequence Used", default=False, copy=False, readonly=True
)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if not vals.get("name"):
if self.is_using_quotation_number(vals):
if self.is_using_quotation_number(vals):
if not vals.get("name"):
company_id = vals.get("company_id", self.env.company.id)
sequence = (
self.with_company(company_id)
.env["ir.sequence"]
.next_by_code("sale.quotation")
)
vals["name"] = sequence or "/"
vals["quotation_seq_used"] = True
return super().create(vals_list)

@api.model
Expand All @@ -43,23 +48,23 @@ def copy(self, default=None):
default["origin"] = self.name
return super().copy(default)

def get_sale_order_seq(self):
self.ensure_one()
return self.env["ir.sequence"].next_by_code("sale.order")

def action_confirm(self):
sequence = self.env["ir.sequence"].search(
[("code", "=", "sale.quotation")], limit=1
)
for order in self:
if sequence and self.name[: len(sequence.prefix)] != sequence.prefix:
if not self.quotation_seq_used:
continue
if order.state not in ("draft", "sent") or order.company_id.keep_name_so:
continue
if order.origin and order.origin != "":
quo = order.origin + ", " + order.name
else:
quo = order.name
sequence = (
self.with_company(order.company_id.id)
.env["ir.sequence"]
.next_by_code("sale.order")
)
order.write({"origin": quo, "name": sequence})
sequence = order.with_company(order.company_id.id).get_sale_order_seq()
order.write({"origin": quo, "name": sequence, "quotation_seq_used": False})
return super().action_confirm()

0 comments on commit 94e7bba

Please sign in to comment.