Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
4
sale_quotation_number/models/__init__.py
Executable file
4
sale_quotation_number/models/__init__.py
Executable file
@@ -0,0 +1,4 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||
|
||||
from . import res_company
|
||||
from . import sale_order
|
||||
27
sale_quotation_number/models/res_company.py
Executable file
27
sale_quotation_number/models/res_company.py
Executable file
@@ -0,0 +1,27 @@
|
||||
# © 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 fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
keep_name_so = fields.Boolean(
|
||||
string="Use Same Enumeration",
|
||||
help="If this is unchecked, quotations use a different sequence from "
|
||||
"sale orders",
|
||||
default=True,
|
||||
)
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
keep_name_so = fields.Boolean(
|
||||
related="company_id.keep_name_so",
|
||||
readonly=False,
|
||||
)
|
||||
65
sale_quotation_number/models/sale_order.py
Executable file
65
sale_quotation_number/models/sale_order.py
Executable file
@@ -0,0 +1,65 @@
|
||||
# © 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, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
@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):
|
||||
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 vals.get("company_id"):
|
||||
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):
|
||||
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:
|
||||
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})
|
||||
return super().action_confirm()
|
||||
Reference in New Issue
Block a user