diff --git a/contract/__manifest__.py b/contract/__manifest__.py index 9d5ac02d..eaa39d61 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -1,14 +1,14 @@ # Copyright 2004-2010 OpenERP SA # Copyright 2014-2017 Tecnativa - Pedro M. Baeza # Copyright 2015 Domatix -# Copyright 2016-2017 Tecnativa - Carlos Dauden +# Copyright 2016-2018 Tecnativa - Carlos Dauden # Copyright 2017 Tecnativa - Vicent Cubells # Copyright 2016-2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Contracts Management - Recurring', - 'version': '11.0.1.4.0', + 'version': '11.0.1.4.3', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "OpenERP SA, " diff --git a/contract/models/account_analytic_account.py b/contract/models/account_analytic_account.py index 05b2182b..09b99d49 100644 --- a/contract/models/account_analytic_account.py +++ b/contract/models/account_analytic_account.py @@ -1,7 +1,7 @@ # Copyright 2004-2010 OpenERP SA # Copyright 2014 Angel Moya # Copyright 2015 Pedro M. Baeza -# Copyright 2016-2017 Carlos Dauden +# Copyright 2016-2018 Carlos Dauden # Copyright 2016-2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -145,6 +145,8 @@ class AccountAnalyticAccount(models.Model): new_lines = [] for contract_line in contract.recurring_invoice_line_ids: vals = contract_line._convert_to_write(contract_line.read()[0]) + # Remove template link field named as analytic account field + vals.pop('analytic_account_id', False) new_lines.append((0, 0, vals)) return new_lines @@ -162,17 +164,9 @@ class AccountAnalyticAccount(models.Model): return relativedelta(years=interval) @api.model - def _insert_markers(self, line, date_start, next_date, date_format): - contract = line.analytic_account_id - if contract.recurring_invoicing_type == 'pre-paid': - date_from = date_start - date_to = next_date - relativedelta(days=1) - else: - date_from = (date_start - - self.get_relative_delta(contract.recurring_rule_type, - contract.recurring_interval) + - relativedelta(days=1)) - date_to = date_start + def _insert_markers(self, line, date_format): + date_from = fields.Date.from_string(line.date_from) + date_to = fields.Date.from_string(line.date_to) name = line.name name = name.replace('#START#', date_from.strftime(date_format)) name = name.replace('#END#', date_to.strftime(date_format)) @@ -191,16 +185,12 @@ class AccountAnalyticAccount(models.Model): invoice_line._onchange_product_id() invoice_line_vals = invoice_line._convert_to_write(invoice_line._cache) # Insert markers - name = line.name contract = line.analytic_account_id - if 'old_date' in self.env.context and 'next_date' in self.env.context: - lang_obj = self.env['res.lang'] - lang = lang_obj.search( - [('code', '=', contract.partner_id.lang)]) - date_format = lang.date_format or '%m/%d/%Y' - name = self._insert_markers( - line, self.env.context['old_date'], - self.env.context['next_date'], date_format) + lang_obj = self.env['res.lang'] + lang = lang_obj.search( + [('code', '=', contract.partner_id.lang)]) + date_format = lang.date_format or '%m/%d/%Y' + name = self._insert_markers(line, date_format) invoice_line_vals.update({ 'name': name, 'account_analytic_id': contract.id, @@ -252,7 +242,8 @@ class AccountAnalyticAccount(models.Model): invoice = self.env['account.invoice'].create(invoice_vals) for line in self.recurring_invoice_line_ids: invoice_line_vals = self._prepare_invoice_line(line, invoice.id) - self.env['account.invoice.line'].create(invoice_line_vals) + if invoice_line_vals: + self.env['account.invoice.line'].create(invoice_line_vals) invoice.compute_taxes() return invoice diff --git a/contract/models/account_analytic_invoice_line.py b/contract/models/account_analytic_invoice_line.py index 7dd96f71..188d4c81 100644 --- a/contract/models/account_analytic_invoice_line.py +++ b/contract/models/account_analytic_invoice_line.py @@ -1,10 +1,12 @@ # © 2004-2010 OpenERP SA # © 2014 Angel Moya # © 2015 Pedro M. Baeza -# © 2016 Carlos Dauden +# © 2016-2018 Carlos Dauden # Copyright 2016-2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from dateutil.relativedelta import relativedelta + from odoo import api, fields, models from odoo.addons import decimal_precision as dp from odoo.exceptions import ValidationError @@ -59,6 +61,16 @@ class AccountAnalyticInvoiceLine(models.Model): default=10, help="Sequence of the contract line when displaying contracts", ) + date_from = fields.Date( + string='Date From', + compute='_compute_date_from', + help='Date from invoiced period', + ) + date_to = fields.Date( + string='Date To', + compute='_compute_date_to', + help='Date to invoiced period', + ) @api.multi @api.depends('quantity', 'price_unit', 'discount') @@ -73,6 +85,47 @@ class AccountAnalyticInvoiceLine(models.Model): else: line.price_subtotal = subtotal + def _compute_date_from(self): + # When call from template line.analytic_account_id comodel is + # 'account.analytic.contract', + if self._name != 'account.analytic.invoice.line': + return + for line in self: + contract = line.analytic_account_id + date_start = ( + self.env.context.get('old_date') or fields.Date.from_string( + contract.recurring_next_date or fields.Date.today()) + ) + if contract.recurring_invoicing_type == 'pre-paid': + date_from = date_start + else: + date_from = (date_start - contract.get_relative_delta( + contract.recurring_rule_type, + contract.recurring_interval) + relativedelta(days=1)) + line.date_from = fields.Date.to_string(date_from) + + def _compute_date_to(self): + # When call from template line.analytic_account_id comodel is + # 'account.analytic.contract', + if self._name != 'account.analytic.invoice.line': + return + for line in self: + contract = line.analytic_account_id + date_start = ( + self.env.context.get('old_date') or fields.Date.from_string( + contract.recurring_next_date or fields.Date.today()) + ) + next_date = ( + self.env.context.get('next_date') or + date_start + contract.get_relative_delta( + contract.recurring_rule_type, contract.recurring_interval) + ) + if contract.recurring_invoicing_type == 'pre-paid': + date_to = next_date - relativedelta(days=1) + else: + date_to = date_start + line.date_to = fields.Date.to_string(date_to) + @api.multi @api.constrains('discount') def _check_discount(self): diff --git a/contract/models/res_partner.py b/contract/models/res_partner.py index cd9c30ce..f175912a 100644 --- a/contract/models/res_partner.py +++ b/contract/models/res_partner.py @@ -18,8 +18,7 @@ class ResPartner(models.Model): for partner in self: partner.contract_count = Contract.search_count([ ('recurring_invoices', '=', True), - ('partner_id', '=', partner.id), - ('date_start', '<=', today), + ('partner_id', 'child_of', partner.ids), '|', ('date_end', '=', False), ('date_end', '>=', today), @@ -37,9 +36,10 @@ class ResPartner(models.Model): self.env.context, search_default_recurring_invoices=True, search_default_not_finished=True, + search_default_partner_id=self.id, default_partner_id=self.id, default_recurring_invoices=True, + default_pricelist_id=self.property_product_pricelist.id, ), - domain=[('partner_id', '=', self.id)], ) return res diff --git a/contract/views/account_analytic_account_view.xml b/contract/views/account_analytic_account_view.xml index 1a96b0dc..b915b90b 100644 --- a/contract/views/account_analytic_account_view.xml +++ b/contract/views/account_analytic_account_view.xml @@ -116,12 +116,11 @@ account.analytic.account + + + - - - -