|
|
@ -1,10 +1,12 @@ |
|
|
|
# © 2004-2010 OpenERP SA |
|
|
|
# © 2014 Angel Moya <angel.moya@domatix.com> |
|
|
|
# © 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
|
|
|
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> |
|
|
|
# © 2016-2018 Carlos Dauden <carlos.dauden@tecnativa.com> |
|
|
|
# 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): |
|
|
|