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
66 lines (56 loc) · 2.23 KB
/
sale_order.py
File metadata and controls
66 lines (56 loc) · 2.23 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
64
65
66
# © 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"
quotation_seq_used = fields.Boolean(
string="Quotation Sequence Used", default=False, copy=False, readonly=True
)
@api.model
def create(self, vals):
if self.is_using_quotation_number(vals):
sequence = self.get_quotation_seq()
vals.update({"name": sequence or "/", "quotation_seq_used": True})
return super(SaleOrder, self).create(vals)
@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(SaleOrder, self).copy(default)
@api.model
def get_quotation_seq(self):
return self.env["ir.sequence"].next_by_code("sale.quotation")
def get_sale_order_seq(self):
self.ensure_one()
return self.env["ir.sequence"].next_by_code("sale.order")
def _action_confirm(self):
for order in self:
if not (
order.state == "sale"
and order.quotation_seq_used
and not order.company_id.keep_name_so
):
continue
quo = ""
if order.origin and order.origin != "":
quo = order.origin + ", " + order.name
else:
quo = order.name
sequence = order.get_sale_order_seq()
order.write({"origin": quo, "name": sequence, "quotation_seq_used": False})
return super()._action_confirm()