mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract: Add computed dates from/to period invoiced (#140)
This commit is contained in:
committed by
Pedro M. Baeza
parent
c6e7f25486
commit
81e14cdce0
@@ -1,14 +1,14 @@
|
|||||||
# Copyright 2004-2010 OpenERP SA
|
# Copyright 2004-2010 OpenERP SA
|
||||||
# Copyright 2014-2017 Tecnativa - Pedro M. Baeza
|
# Copyright 2014-2017 Tecnativa - Pedro M. Baeza
|
||||||
# Copyright 2015 Domatix
|
# Copyright 2015 Domatix
|
||||||
# Copyright 2016-2017 Tecnativa - Carlos Dauden
|
# Copyright 2016-2018 Tecnativa - Carlos Dauden
|
||||||
# Copyright 2017 Tecnativa - Vicent Cubells
|
# Copyright 2017 Tecnativa - Vicent Cubells
|
||||||
# Copyright 2016-2017 LasLabs Inc.
|
# Copyright 2016-2017 LasLabs Inc.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Contracts Management - Recurring',
|
'name': 'Contracts Management - Recurring',
|
||||||
'version': '11.0.1.4.0',
|
'version': '11.0.1.4.1',
|
||||||
'category': 'Contract Management',
|
'category': 'Contract Management',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'author': "OpenERP SA, "
|
'author': "OpenERP SA, "
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Copyright 2004-2010 OpenERP SA
|
# Copyright 2004-2010 OpenERP SA
|
||||||
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
|
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
|
||||||
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||||
# Copyright 2016-2017 Carlos Dauden <carlos.dauden@tecnativa.com>
|
# Copyright 2016-2018 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||||
# Copyright 2016-2017 LasLabs Inc.
|
# Copyright 2016-2017 LasLabs Inc.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
@@ -162,17 +162,9 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
return relativedelta(years=interval)
|
return relativedelta(years=interval)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _insert_markers(self, line, date_start, next_date, date_format):
|
def _insert_markers(self, line, date_format):
|
||||||
contract = line.analytic_account_id
|
date_from = fields.Date.from_string(line.date_from)
|
||||||
if contract.recurring_invoicing_type == 'pre-paid':
|
date_to = fields.Date.from_string(line.date_to)
|
||||||
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
|
|
||||||
name = line.name
|
name = line.name
|
||||||
name = name.replace('#START#', date_from.strftime(date_format))
|
name = name.replace('#START#', date_from.strftime(date_format))
|
||||||
name = name.replace('#END#', date_to.strftime(date_format))
|
name = name.replace('#END#', date_to.strftime(date_format))
|
||||||
@@ -191,16 +183,12 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
invoice_line._onchange_product_id()
|
invoice_line._onchange_product_id()
|
||||||
invoice_line_vals = invoice_line._convert_to_write(invoice_line._cache)
|
invoice_line_vals = invoice_line._convert_to_write(invoice_line._cache)
|
||||||
# Insert markers
|
# Insert markers
|
||||||
name = line.name
|
|
||||||
contract = line.analytic_account_id
|
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_obj = self.env['res.lang']
|
lang = lang_obj.search(
|
||||||
lang = lang_obj.search(
|
[('code', '=', contract.partner_id.lang)])
|
||||||
[('code', '=', contract.partner_id.lang)])
|
date_format = lang.date_format or '%m/%d/%Y'
|
||||||
date_format = lang.date_format or '%m/%d/%Y'
|
name = self._insert_markers(line, date_format)
|
||||||
name = self._insert_markers(
|
|
||||||
line, self.env.context['old_date'],
|
|
||||||
self.env.context['next_date'], date_format)
|
|
||||||
invoice_line_vals.update({
|
invoice_line_vals.update({
|
||||||
'name': name,
|
'name': name,
|
||||||
'account_analytic_id': contract.id,
|
'account_analytic_id': contract.id,
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
# © 2004-2010 OpenERP SA
|
# © 2004-2010 OpenERP SA
|
||||||
# © 2014 Angel Moya <angel.moya@domatix.com>
|
# © 2014 Angel Moya <angel.moya@domatix.com>
|
||||||
# © 2015 Pedro M. Baeza <pedro.baeza@tecnativa.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.
|
# Copyright 2016-2017 LasLabs Inc.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# 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 import api, fields, models
|
||||||
from odoo.addons import decimal_precision as dp
|
from odoo.addons import decimal_precision as dp
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
@@ -59,6 +61,16 @@ class AccountAnalyticInvoiceLine(models.Model):
|
|||||||
default=10,
|
default=10,
|
||||||
help="Sequence of the contract line when displaying contracts",
|
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.multi
|
||||||
@api.depends('quantity', 'price_unit', 'discount')
|
@api.depends('quantity', 'price_unit', 'discount')
|
||||||
@@ -73,6 +85,47 @@ class AccountAnalyticInvoiceLine(models.Model):
|
|||||||
else:
|
else:
|
||||||
line.price_subtotal = subtotal
|
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.multi
|
||||||
@api.constrains('discount')
|
@api.constrains('discount')
|
||||||
def _check_discount(self):
|
def _check_discount(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user