forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsale_order.py
More file actions
63 lines (55 loc) · 2.19 KB
/
sale_order.py
File metadata and controls
63 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# © 2010-2012 Andy Lu <andy.lu@elico-corp.com> (Elico Corp)
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2017 valentin vinagre <valentin.vinagre@qubiq.es> (QubiQ)
# © 2020 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import api, fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
confirmed_before = fields.Boolean(copy=False)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if self.is_using_quotation_number(vals):
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 "/"
return super().create(vals_list)
@api.model
def is_using_quotation_number(self, vals):
company = False
if "company_id" in vals:
company = self.env["res.company"].browse(vals.get("company_id"))
else:
company = self.env.company
return not company.keep_name_so
def copy(self, default=None):
self.ensure_one()
if default is None:
default = {}
if self.origin and self.origin != "":
default["origin"] = self.origin + ", " + self.name
else:
default["origin"] = self.name
return super().copy(default)
def action_confirm(self):
for order in self:
if order.confirmed_before:
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, "confirmed_before": True})
return super().action_confirm()