From 9ac53b07dbc8bf6e188b139567e1b6f69ad60670 Mon Sep 17 00:00:00 2001 From: Arnaud Joset Date: Tue, 2 Nov 2021 11:22:41 +0100 Subject: [PATCH 1/2] [IMP] sale,sale_management: adaption for subscription override of SO Before this commit, the sale module could not be used to manage subscriptions in an override. This commit adapts the sale module to https://github.com/odoo/enterprise/pull/21825 taskid: 2568007 --- addons/sale/data/sale_demo.xml | 1 - addons/sale/models/sale_order.py | 19 ++++++++++--------- addons/sale/models/sale_order_line.py | 3 +-- addons/sale/views/sale_order_views.xml | 6 +++--- addons/sale_coupon/models/__init__.py | 1 + addons/sale_coupon/models/sale_order.py | 1 - addons/sale_coupon/models/sale_order_line.py | 12 ++++++++++++ addons/sale_management/models/sale_order.py | 4 ++++ addons/sale_project/models/sale_order_line.py | 3 +-- addons/sale_stock/models/sale_order_line.py | 5 ++--- addons/sale_stock/tests/test_create_perf.py | 6 +++--- .../sale_timesheet/tests/test_sale_service.py | 5 ----- .../static/tests/tours/main_flow.js | 4 ++-- 13 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 addons/sale_coupon/models/sale_order_line.py diff --git a/addons/sale/data/sale_demo.xml b/addons/sale/data/sale_demo.xml index 19ab8581ae4..3f5d78eac42 100644 --- a/addons/sale/data/sale_demo.xml +++ b/addons/sale/data/sale_demo.xml @@ -236,7 +236,6 @@ - Test/001 diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 4c88e874a6b..54ed61650f2 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -841,10 +841,11 @@ class SaleOrder(models.Model): lines_to_recompute.discount = 0.0 lines_to_recompute._compute_discount() self.show_update_pricelist = False - self.message_post(body=_( - "Product prices have been recomputed according to pricelist %s.", - self.pricelist_id._get_html_link(), - )) + if self.partner_id and self.id: + self.message_post(body=_( + "Product prices have been recomputed according to pricelist %s.", + self.pricelist_id._get_html_link(), + )) # INVOICING # @@ -916,9 +917,9 @@ class SaleOrder(models.Model): def _get_invoice_grouping_keys(self): return ['company_id', 'partner_id', 'currency_id'] - @api.model - def _nothing_to_invoice_error(self): - return UserError(_( + def _nothing_to_invoice_error_message(self): + self.ensure_one() + return _( "There is nothing to invoice!\n\n" "Reason(s) of this behavior could be:\n" "- You should deliver your products before invoicing them: Click on the \"truck\" icon " @@ -927,7 +928,7 @@ class SaleOrder(models.Model): "\"Sales\" tab and modify invoicing policy from \"delivered quantities\" to \"ordered " "quantities\". For Services, you should modify the Service Invoicing Policy to " "'Prepaid'." - )) + ) def _get_invoiceable_lines(self, final=False): """Return the invoiceable lines for order `self`.""" @@ -1007,7 +1008,7 @@ class SaleOrder(models.Model): invoice_vals_list.append(invoice_vals) if not invoice_vals_list: - raise self._nothing_to_invoice_error() + raise UserError(order._nothing_to_invoice_error_message()) # 2) Manage 'grouped' parameter: group by (partner_id, currency_id). if not grouped: diff --git a/addons/sale/models/sale_order_line.py b/addons/sale/models/sale_order_line.py index 67d98c6aa89..ec23f36dc43 100644 --- a/addons/sale/models/sale_order_line.py +++ b/addons/sale/models/sale_order_line.py @@ -731,7 +731,7 @@ class SaleOrderLine(models.Model): calculated from the ordered quantity. Otherwise, the quantity delivered is used. """ for line in self: - if line.state in ['sale', 'done']: + if line.state in ['sale', 'done'] and not line.display_type: if line.product_id.invoice_policy == 'order': line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced else: @@ -904,7 +904,6 @@ class SaleOrderLine(models.Model): } #=== CRUD METHODS ===# - def _add_precomputed_values(self, vals_list): """ In the specific case where the discount is provided in the create values without being rounded, we have to 'manually' round it otherwise it won't be, diff --git a/addons/sale/views/sale_order_views.xml b/addons/sale/views/sale_order_views.xml index 7e3a0830133..a1d9dbafa36 100644 --- a/addons/sale/views/sale_order_views.xml +++ b/addons/sale/views/sale_order_views.xml @@ -195,10 +195,10 @@ string="Void Transaction" data-hotkey="shift+v" confirm="Are you sure you want to void the authorized transaction? This action can't be undone." attrs="{'invisible': [('authorized_transaction_ids', '=', [])]}"/> -