Nikul Chaudhary
5 years ago
6 changed files with 82 additions and 102 deletions
-
1contract_sale/__init__.py
-
4contract_sale/models/__init__.py
-
73contract_sale/models/contract.py
-
11contract_sale/models/sale_order.py
-
1contract_sale_invoicing/models/__init__.py
-
76contract_sale_invoicing/models/contract.py
@ -1,2 +1 @@ |
|||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html |
|||
from . import models |
@ -1,4 +0,0 @@ |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import contract |
|||
from . import sale_order |
@ -1,73 +0,0 @@ |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
from odoo import api, models |
|||
|
|||
|
|||
class ContractContract(models.Model): |
|||
_inherit = 'contract.contract' |
|||
|
|||
@api.multi |
|||
def _prepare_recurring_invoices_values(self, date_ref=False): |
|||
""" |
|||
overwrite Base Contract Method |
|||
""" |
|||
invoices_values = [] |
|||
for contract in self: |
|||
if not date_ref: |
|||
date_ref = contract.recurring_next_date |
|||
if not date_ref: |
|||
# this use case is possible when recurring_create_invoice is |
|||
# called for a finished contract |
|||
continue |
|||
contract_lines = contract._get_lines_to_invoice(date_ref) |
|||
if not contract_lines: |
|||
continue |
|||
invoice_values = contract._prepare_invoice(date_ref) |
|||
|
|||
# Search Contract in sale order |
|||
order_ids = self.env['sale.order'].search([ |
|||
('partner_id', '=', contract.partner_id.id), |
|||
('contract_id', '=', contract.id), |
|||
]) |
|||
|
|||
for line in contract_lines: |
|||
invoice_values.setdefault('invoice_line_ids', []) |
|||
invoice_line_values = line._prepare_invoice_line( |
|||
invoice_id=False |
|||
) |
|||
if invoice_line_values: |
|||
|
|||
# Check Invoice and If It's Not Created then Updated Qty |
|||
for order_id in order_ids: |
|||
invoice_ids =\ |
|||
order_id.order_line.mapped('invoice_lines') |
|||
if not invoice_ids: |
|||
for line in order_id.order_line: |
|||
if line.product_id.id == invoice_line_values.\ |
|||
get('product_id', False): |
|||
invoice_line_values['quantity' |
|||
] += line.product_uom_qty |
|||
|
|||
invoice_values['invoice_line_ids'].append( |
|||
(0, 0, invoice_line_values) |
|||
) |
|||
|
|||
invoices_values.append(invoice_values) |
|||
contract_lines._update_recurring_next_date() |
|||
return invoices_values |
|||
|
|||
@api.depends('contract_line_ids') |
|||
def _compute_sale_order_count(self): |
|||
super(ContractContract, self)._compute_sale_order_count() |
|||
contract_count = len( |
|||
self.contract_line_ids. |
|||
mapped('sale_order_line_id.order_id.contract_id')) or 0 |
|||
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 |
@ -1,11 +0,0 @@ |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class SaleOrder(models.Model): |
|||
_inherit = 'sale.order' |
|||
|
|||
contract_id = fields.Many2one( |
|||
comodel_name="contract.contract", |
|||
string="Contract", |
|||
) |
@ -1,3 +1,4 @@ |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import sale_order |
|||
from . import contract |
Write
Preview
Loading…
Cancel
Save
Reference in new issue