From 3d3cf2131b7d1c9a8056ef7b99ca9d12d778b235 Mon Sep 17 00:00:00 2001 From: Guidomadormo <68272608+Guidomadormo@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:34:28 +0100 Subject: [PATCH] [UPD] sale_quotation_number: fix revision naming for sale orders --- sale_quotation_number/__manifest__.py | 2 +- sale_quotation_number/models/sale_order.py | 19 ++++++++++--------- .../tests/test_sale_order.py | 6 ++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sale_quotation_number/__manifest__.py b/sale_quotation_number/__manifest__.py index 9db76a56c29..a54edb46096 100644 --- a/sale_quotation_number/__manifest__.py +++ b/sale_quotation_number/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Sale Quotation Numeration", "summary": "Different sequence for sale quotations", - "version": "16.0.1.1.0", + "version": "16.0.1.1.1", "category": "Sales Management", "website": "https://github.com/OCA/sale-workflow", "author": "Elico Corp, " diff --git a/sale_quotation_number/models/sale_order.py b/sale_quotation_number/models/sale_order.py index b48634d8c06..5209b9a5714 100644 --- a/sale_quotation_number/models/sale_order.py +++ b/sale_quotation_number/models/sale_order.py @@ -13,20 +13,21 @@ class SaleOrder(models.Model): @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 "/" + 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 "company_id" in vals: + if vals.get("company_id"): company = self.env["res.company"].browse(vals.get("company_id")) else: company = self.env.company diff --git a/sale_quotation_number/tests/test_sale_order.py b/sale_quotation_number/tests/test_sale_order.py index 9c649e4e8ac..f4c315ce88f 100644 --- a/sale_quotation_number/tests/test_sale_order.py +++ b/sale_quotation_number/tests/test_sale_order.py @@ -106,3 +106,9 @@ def test_sequence_assignment(self): next_name = sequence_id.get_next_char(sequence_id.number_next_actual) self.order_company1.action_confirm() self.assertEqual(next_name, self.order_company1.name) + + def test_create_with_specific_name(self): + order = self.sale_order_model.create( + {"name": "CustomName", "partner_id": self.env.ref("base.res_partner_1").id} + ) + self.assertEqual(order.name, "CustomName")