From 89097b52d99378d438bc66b25121daf4d0bfb79e Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Fri, 13 Dec 2019 13:28:02 +0530 Subject: [PATCH] [RFC] contract_sale v12 --- contract_sale/models/__init__.py | 4 ++++ contract_sale/models/contract.py | 25 +++++++++++++++++++++++++ contract_sale/models/sale_order.py | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 contract_sale/models/__init__.py create mode 100644 contract_sale/models/contract.py create mode 100644 contract_sale/models/sale_order.py diff --git a/contract_sale/models/__init__.py b/contract_sale/models/__init__.py new file mode 100644 index 00000000..f0981283 --- /dev/null +++ b/contract_sale/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import contract +from . import sale_order diff --git a/contract_sale/models/contract.py b/contract_sale/models/contract.py new file mode 100644 index 00000000..e5773ac9 --- /dev/null +++ b/contract_sale/models/contract.py @@ -0,0 +1,25 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class ContractContract(models.Model): + _inherit = 'contract.contract' + + @api.multi + def _prepare_recurring_invoices_values(self, date_ref=False): + invoices_values = super(ContractContract, self)._prepare_recurring_invoices_values(date_ref=date_ref) + return invoices_values + + def _compute_sale_order_count(self): + super(ContractContract, self)._compute_sale_order_count() + contract_count = self.contract_line_ids.mapped('sale_order_line_id.order_id.contract_id') + self.sale_order_count += contract_count + + @api.multi + def action_view_sales_orders(self): + res = super(ContractContract, self).action_view_sales_orders() + contracts = self.contract_line_ids.mapped( + 'sale_order_line_id.order_id.contract_id' + ) + res.get('domain')[0][2].extend(contracts) + return res diff --git a/contract_sale/models/sale_order.py b/contract_sale/models/sale_order.py new file mode 100644 index 00000000..6c362ae7 --- /dev/null +++ b/contract_sale/models/sale_order.py @@ -0,0 +1,27 @@ +# 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' + + contract_id = fields.Many2one( + comodel_name="contract.contract", + string="Contract" + ) + + @api.multi + def action_confirm(self): + res = super(SaleOrder, self).action_confirm() + invoice_ids = self.env['account.invoice'].search([ + ('partner_id', '=', self.partner_id.id), + ('old_contract_id', '=', self.contract_id.id), + ('state', '=', 'draft')]) + + for invoice_id in invoice_ids: + for order_line in self.order_line: + for invoice_line in invoice_id.invoice_line_ids: + if order_line.product_id.id == invoice_line.product_id.id: + invoice_line.quantity += order_line.product_uom_qty + self.action_invoice_create() + return res