-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP]sale_quotation_number: Boolean to determine whether quotation se…
…quence has been used
- Loading branch information
1 parent
213271c
commit 1130c42
Showing
1 changed file
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,16 @@ | |
# © 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: | ||
|
@@ -22,6 +26,7 @@ def create(self, vals_list): | |
.next_by_code("sale.quotation") | ||
) | ||
vals["name"] = sequence or "/" | ||
vals["quotation_seq_used"] = True | ||
return super().create(vals_list) | ||
|
||
@api.model | ||
|
@@ -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.with_company(order.company_id.id).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.get_sale_order_seq() | ||
order.write({"origin": quo, "name": sequence, "quotation_seq_used": False}) | ||
return super().action_confirm() |