From d24b7503cd88fd6f0d783a43b007c59d52279d88 Mon Sep 17 00:00:00 2001 From: Kirti Choudhary Date: Wed, 20 Dec 2017 14:49:11 +0530 Subject: [PATCH 1/4] [IMP] sale: Rename 'Check/Set Price' buttons for more clarify relabel "Check price" -> "Get rate" relabel "Set Price" -> "Add to order" Task ID : 33126 --- addons/delivery/views/delivery_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/delivery/views/delivery_view.xml b/addons/delivery/views/delivery_view.xml index 1c5b6f6134f..ec1f4e1d475 100644 --- a/addons/delivery/views/delivery_view.xml +++ b/addons/delivery/views/delivery_view.xml @@ -290,8 +290,8 @@
-
From 3d46887d38e970f4932cef1bd4a887f6629151fe Mon Sep 17 00:00:00 2001 From: Kirti Choudhary Date: Tue, 19 Jun 2018 17:16:29 +0530 Subject: [PATCH 2/4] [IMP] sale: Change the default invoicing method if there are downpayments Purpose ======= Currently the default invoicing method is not very clear. Specification ============= Currently the result is not really correct. We can propose to deduct the down payment even if there are no down payments on the sales order. Now the option to deduct down payments will be selected if there is a downpayment line on the sales order and if there exists at least one invoice linked to the sales order that is not cancelled. Task ID : 33126 --- addons/sale/wizard/sale_make_invoice_advance.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index 69c09932b66..c7187e816c0 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -21,11 +21,11 @@ class SaleAdvancePaymentInv(models.TransientModel): if self._count() == 1: sale_obj = self.env['sale.order'] order = sale_obj.browse(self._context.get('active_ids'))[0] - if all([line.product_id.invoice_policy == 'order' for line in order.order_line]) or order.invoice_count: + if order.order_line.filtered(lambda dp: dp.is_downpayment) and order.invoice_ids.filtered(lambda invoice: invoice.state != 'cancel'): return 'all' - else: - return 'all' - return 'delivered' + else: + return 'delivered' + return 'all' @api.model def _default_product_id(self): From 752a6843d181228501cb252b9f492463fc835d18 Mon Sep 17 00:00:00 2001 From: Mitali Patel Date: Mon, 19 Mar 2018 16:54:44 +0530 Subject: [PATCH 3/4] [IMP] delivery: Improve the SO invoice status Purpose ======= If a SO is only containing lines for which the product is invoiced on the delivered quantity, the sales order is marked as 'Nothing to Invoice'. If I add a delivery line, the SO becomes 'To Invoice'. There is not really a use case in the real life where you will invoice the delivery fees before invoicing what has been really delivered. Specification ============= If an order: - contains delivery lines or downpayment lines - If the product on the other lines are invoiced on the delivered quantity - Nothing has been delivery or can be invoiced for theses lines Set the invoice status of the sales order to 'Nothing to invoice' instead of 'To Invoice' Task ID : 33126 --- addons/delivery/models/sale_order.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/delivery/models/sale_order.py b/addons/delivery/models/sale_order.py index e08f37b135e..a509b50edae 100644 --- a/addons/delivery/models/sale_order.py +++ b/addons/delivery/models/sale_order.py @@ -111,6 +111,15 @@ class SaleOrder(models.Model): sol = SaleOrderLine.sudo().create(values) return sol + @api.depends('state', 'order_line.invoice_status', 'order_line.invoice_lines', + 'order_line.is_delivery', 'order_line.is_downpayment', 'order_line.product_id.invoice_policy') + def _get_invoiced(self): + super(SaleOrder, self)._get_invoiced() + for order in self: + order_line = order.order_line.filtered(lambda x: not x.is_delivery and not x.is_downpayment) + if all(line.product_id.invoice_policy == 'delivery' and line.invoice_status == 'no' for line in order_line): + order.update({'invoice_status': 'no'}) + class SaleOrderLine(models.Model): _inherit = 'sale.order.line' From eebeb39da54e6671c4ced7ddbd24adbd3a7952f8 Mon Sep 17 00:00:00 2001 From: Kirti Choudhary Date: Thu, 21 Dec 2017 16:18:38 +0530 Subject: [PATCH 4/4] [IMP] sale: Unlink the down payment on a SO if the invoice is unlinked Purpose ======= When we create a downpayment line of SO and when we delete Invoice of downpayment then so line for downpayment is not deleted. Specification ============= Remove the downpayment line in the SO if the related invoice is deleted Task ID :33126 --- addons/sale/models/account_invoice.py | 8 ++++++++ addons/sale/models/sale.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index 24cb6aa7bb1..295f53db3a5 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -34,6 +34,14 @@ class AccountInvoice(models.Model): if fiscal_position: self.fiscal_position_id = fiscal_position + @api.multi + def unlink(self): + downpayment_lines = self.mapped('invoice_line_ids.sale_line_ids').filtered(lambda line: line.is_downpayment) + res = super(AccountInvoice, self).unlink() + if downpayment_lines: + downpayment_lines.unlink() + return res + @api.onchange('partner_id', 'company_id') def _onchange_delivery_address(self): addr = self.partner_id.address_get(['delivery']) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 2b1d9e886a0..d28c315fb02 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1209,7 +1209,7 @@ class SaleOrderLine(models.Model): @api.multi def unlink(self): - if self.filtered(lambda x: x.state in ('sale', 'done')): + if self.filtered(lambda line: line.state in ('sale', 'done') and (line.invoice_lines or not line.is_downpayment)): raise UserError(_('You can not remove an order line once the sales order is confirmed.\nYou should rather set the quantity to 0.')) return super(SaleOrderLine, self).unlink()