mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP+FIX] contract: Several things:
* [IMP] Add computed dates from/to period invoiced (#140) * [IMP] Improve partner contract smartbutton * [FIX] Onchange contract template raise error * [FIX] Invalid pricelist name
This commit is contained in:
committed by
Pedro M. Baeza
parent
a808ff1b33
commit
620cbd06a4
@@ -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.3',
|
||||||
'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).
|
||||||
|
|
||||||
@@ -145,6 +145,8 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
new_lines = []
|
new_lines = []
|
||||||
for contract_line in contract.recurring_invoice_line_ids:
|
for contract_line in contract.recurring_invoice_line_ids:
|
||||||
vals = contract_line._convert_to_write(contract_line.read()[0])
|
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))
|
new_lines.append((0, 0, vals))
|
||||||
return new_lines
|
return new_lines
|
||||||
|
|
||||||
@@ -162,17 +164,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 +185,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(
|
name = self._insert_markers(line, date_format)
|
||||||
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,
|
||||||
@@ -252,6 +242,7 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
invoice = self.env['account.invoice'].create(invoice_vals)
|
invoice = self.env['account.invoice'].create(invoice_vals)
|
||||||
for line in self.recurring_invoice_line_ids:
|
for line in self.recurring_invoice_line_ids:
|
||||||
invoice_line_vals = self._prepare_invoice_line(line, invoice.id)
|
invoice_line_vals = self._prepare_invoice_line(line, invoice.id)
|
||||||
|
if invoice_line_vals:
|
||||||
self.env['account.invoice.line'].create(invoice_line_vals)
|
self.env['account.invoice.line'].create(invoice_line_vals)
|
||||||
invoice.compute_taxes()
|
invoice.compute_taxes()
|
||||||
return invoice
|
return invoice
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ class ResPartner(models.Model):
|
|||||||
for partner in self:
|
for partner in self:
|
||||||
partner.contract_count = Contract.search_count([
|
partner.contract_count = Contract.search_count([
|
||||||
('recurring_invoices', '=', True),
|
('recurring_invoices', '=', True),
|
||||||
('partner_id', '=', partner.id),
|
('partner_id', 'child_of', partner.ids),
|
||||||
('date_start', '<=', today),
|
|
||||||
'|',
|
'|',
|
||||||
('date_end', '=', False),
|
('date_end', '=', False),
|
||||||
('date_end', '>=', today),
|
('date_end', '>=', today),
|
||||||
@@ -37,9 +36,10 @@ class ResPartner(models.Model):
|
|||||||
self.env.context,
|
self.env.context,
|
||||||
search_default_recurring_invoices=True,
|
search_default_recurring_invoices=True,
|
||||||
search_default_not_finished=True,
|
search_default_not_finished=True,
|
||||||
|
search_default_partner_id=self.id,
|
||||||
default_partner_id=self.id,
|
default_partner_id=self.id,
|
||||||
default_recurring_invoices=True,
|
default_recurring_invoices=True,
|
||||||
|
default_pricelist_id=self.property_product_pricelist.id,
|
||||||
),
|
),
|
||||||
domain=[('partner_id', '=', self.id)],
|
|
||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -116,12 +116,11 @@
|
|||||||
<field name="model">account.analytic.account</field>
|
<field name="model">account.analytic.account</field>
|
||||||
<field name="inherit_id" ref="analytic.view_account_analytic_account_search"/>
|
<field name="inherit_id" ref="analytic.view_account_analytic_account_search"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="name" position="after">
|
|
||||||
<field name="partner_id" position="after">
|
<field name="partner_id" position="after">
|
||||||
<!-- Use other field because partner_id already used -->
|
<field name="partner_id" filter_domain="[('partner_id', 'child_of', self)]"
|
||||||
<field name="company_id" filter_domain="[('partner_id', 'child_of', self)]"
|
|
||||||
string="Partner and dependents"/>
|
string="Partner and dependents"/>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="name" position="after">
|
||||||
<field name="journal_id"/>
|
<field name="journal_id"/>
|
||||||
<field name="pricelist_id"/>
|
<field name="pricelist_id"/>
|
||||||
<separator/>
|
<separator/>
|
||||||
|
|||||||
Reference in New Issue
Block a user