Browse Source

Merge pull request #133 from Tecnativa/10.0-contract-automatic_price

[IMP] contract: Automatic prices for lines
pull/135/merge
Dave Lasley 7 years ago
committed by GitHub
parent
commit
817997270e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      contract/README.rst
  2. 2
      contract/__manifest__.py
  3. 91
      contract/i18n/es.po
  4. 13
      contract/migrations/10.0.4.0.0/pre-migration.py
  5. 14
      contract/models/account_analytic_contract.py
  6. 55
      contract/models/account_analytic_invoice_line.py
  7. 14
      contract/tests/test_contract.py
  8. 4
      contract/views/account_analytic_account_view.xml
  9. 6
      contract/views/account_analytic_contract_view.xml

2
contract/README.rst

@ -33,6 +33,8 @@ To use this module, you need to:
* Invoicing type: pre-paid or post-paid. * Invoicing type: pre-paid or post-paid.
#. Add the lines to be invoiced with the product, description, quantity and #. Add the lines to be invoiced with the product, description, quantity and
price. price.
#. You can mark Auto-price? for having a price automatically obtained applying
the pricelist to the product price.
#. You have the possibility to use the markers #START# or #END# in the #. You have the possibility to use the markers #START# or #END# in the
description field to show the start and end date of the invoiced period. description field to show the start and end date of the invoiced period.
#. Choosing between pre-paid and post-paid, you modify the dates that are shown #. Choosing between pre-paid and post-paid, you modify the dates that are shown

2
contract/__manifest__.py

@ -9,7 +9,7 @@
{ {
'name': 'Contracts Management - Recurring', 'name': 'Contracts Management - Recurring',
'version': '10.0.3.3.0',
'version': '10.0.4.0.0',
'category': 'Contract Management', 'category': 'Contract Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': "OpenERP SA, " 'author': "OpenERP SA, "

91
contract/i18n/es.po

@ -1,27 +1,23 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * contract
# * contract
# #
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 10.0\n" "Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-08 01:46+0000\n"
"PO-Revision-Date: 2017-12-08 01:46+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"POT-Creation-Date: 2017-12-23 01:05+0000\n"
"PO-Revision-Date: 2017-12-23 01:05+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Plural-Forms: \n"
#. module: contract #. module: contract
#: model:mail.template,body_html:contract.email_contract_template #: model:mail.template,body_html:contract.email_contract_template
msgid ""
"\n"
msgid "\n"
"<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; \">\n" "<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; \">\n"
" <p>Hello ${object.partner_id.name or ''},</p>\n" " <p>Hello ${object.partner_id.name or ''},</p>\n"
" <p>A new contract has been created: </p>\n" " <p>A new contract has been created: </p>\n"
@ -69,8 +65,7 @@ msgid ""
" </div>\n" " </div>\n"
"</div>\n" "</div>\n"
" " " "
msgstr ""
"\n"
msgstr "\n"
"<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; \">\n" "<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; \">\n"
" <p>Hola ${object.partner_id.name or ''},</p>\n" " <p>Hola ${object.partner_id.name or ''},</p>\n"
" <p>Se ha creado un nuevo contrato: </p>\n" " <p>Se ha creado un nuevo contrato: </p>\n"
@ -196,6 +191,12 @@ msgstr "Ver líneas contables analíticas"
msgid "Analytic Account" msgid "Analytic Account"
msgstr "Cuenta analítica" msgstr "Cuenta analítica"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_line_automatic_price
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_automatic_price
msgid "Auto-price?"
msgstr "¿Precio automático?"
#. module: contract #. module: contract
#: model:ir.actions.act_window,help:contract.account_analytic_contract_action #: model:ir.actions.act_window,help:contract.account_analytic_contract_action
msgid "Click to create a new contract template." msgid "Click to create a new contract template."
@ -229,8 +230,7 @@ msgstr "Contrato"
#: code:addons/contract/models/account_analytic_account.py:139 #: code:addons/contract/models/account_analytic_account.py:139
#, python-format #, python-format
msgid "Contract '%s' start date can't be later than end date" msgid "Contract '%s' start date can't be later than end date"
msgstr ""
"La fecha de inicio del contrato '%s' no puede ser superior a la fecha de fin"
msgstr "La fecha de inicio del contrato '%s' no puede ser superior a la fecha de fin"
#. module: contract #. module: contract
#: model:ir.model,name:contract.model_account_analytic_contract_line #: model:ir.model,name:contract.model_account_analytic_contract_line
@ -239,6 +239,7 @@ msgstr "Lineas de contrato"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_contract_template_id #: model:ir.model.fields,field_description:contract.field_account_analytic_account_contract_template_id
#: model:ir.model.fields,field_description:contract.field_project_project_contract_template_id
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_form #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_form
msgid "Contract Template" msgid "Contract Template"
msgstr "Plantilla de contrato" msgstr "Plantilla de contrato"
@ -263,6 +264,7 @@ msgstr "Contratos"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_create_invoice_visibility #: model:ir.model.fields,field_description:contract.field_account_analytic_account_create_invoice_visibility
#: model:ir.model.fields,field_description:contract.field_project_project_create_invoice_visibility
msgid "Create invoice visibility" msgid "Create invoice visibility"
msgstr "Visibilidad de crear factura" msgstr "Visibilidad de crear factura"
@ -287,6 +289,7 @@ msgstr "Creado en"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_date_end #: model:ir.model.fields,field_description:contract.field_account_analytic_account_date_end
#: model:ir.model.fields,field_description:contract.field_project_project_date_end
#: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search #: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search
msgid "Date End" msgid "Date End"
msgstr "Fecha fin" msgstr "Fecha fin"
@ -298,6 +301,7 @@ msgstr "Fecha de inicio"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_next_date #: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_next_date
#: model:ir.model.fields,field_description:contract.field_project_project_recurring_next_date
msgid "Date of Next Invoice" msgid "Date of Next Invoice"
msgstr "Próxima fecha de factura" msgstr "Próxima fecha de factura"
@ -320,7 +324,7 @@ msgid "Discount (%)"
msgstr "Descuento (%)" msgstr "Descuento (%)"
#. module: contract #. module: contract
#: code:addons/contract/models/account_analytic_invoice_line.py:83
#: code:addons/contract/models/account_analytic_invoice_line.py:126
#, python-format #, python-format
msgid "Discount should be less or equal to 100" msgid "Discount should be less or equal to 100"
msgstr "El descuento debería ser menor o igual a 100" msgstr "El descuento debería ser menor o igual a 100"
@ -328,12 +332,8 @@ msgstr "El descuento debería ser menor o igual a 100"
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_contract_line_discount #: model:ir.model.fields,help:contract.field_account_analytic_contract_line_discount
#: model:ir.model.fields,help:contract.field_account_analytic_invoice_line_discount #: model:ir.model.fields,help:contract.field_account_analytic_invoice_line_discount
msgid ""
"Discount that is applied in generated invoices. It should be less or equal "
"to 100"
msgstr ""
"Descuento que es aplicado en las facturas generadas. Debería ser menor o "
"igual a 100"
msgid "Discount that is applied in generated invoices. It should be less or equal to 100"
msgstr "Descuento que es aplicado en las facturas generadas. Debería ser menor o igual a 100"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_display_name #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_display_name
@ -349,6 +349,7 @@ msgstr "Finalizado"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoices #: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoices
#: model:ir.model.fields,field_description:contract.field_project_project_recurring_invoices
msgid "Generate recurring invoices automatically" msgid "Generate recurring invoices automatically"
msgstr "Generar facturas recurrentes automáticamente." msgstr "Generar facturas recurrentes automáticamente."
@ -364,6 +365,12 @@ msgstr "Agrupar por..."
msgid "ID" msgid "ID"
msgstr "ID (identificación)" msgstr "ID (identificación)"
#. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_contract_line_automatic_price
#: model:ir.model.fields,help:contract.field_account_analytic_invoice_line_automatic_price
msgid "If this is marked, the price will be obtained automatically applying the pricelist to the product. If not, you will be able to introduce a manual price"
msgstr "Si está marcado, el precio se obtendrá automáticamente aplicando la tarifa al producto. Si no, podrá introducir un precio manual"
#. module: contract #. module: contract
#: model:ir.model,name:contract.model_account_invoice #: model:ir.model,name:contract.model_account_invoice
msgid "Invoice" msgid "Invoice"
@ -372,6 +379,7 @@ msgstr "Factura"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoice_line_ids #: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoice_line_ids
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_invoice_line_ids #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_invoice_line_ids
#: model:ir.model.fields,field_description:contract.field_project_project_recurring_invoice_line_ids
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_form #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_form
msgid "Invoice Lines" msgid "Invoice Lines"
msgstr "Líneas de factura" msgstr "Líneas de factura"
@ -384,6 +392,7 @@ msgstr "Facturas"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoicing_type #: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoicing_type
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_invoicing_type #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_invoicing_type
#: model:ir.model.fields,field_description:contract.field_project_project_recurring_invoicing_type
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search
msgid "Invoicing type" msgid "Invoicing type"
msgstr "Tipo de facturación" msgstr "Tipo de facturación"
@ -391,6 +400,7 @@ msgstr "Tipo de facturación"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_journal_id #: model:ir.model.fields,field_description:contract.field_account_analytic_account_journal_id
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_journal_id #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_journal_id
#: model:ir.model.fields,field_description:contract.field_project_project_journal_id
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search
msgid "Journal" msgid "Journal"
msgstr "Diario" msgstr "Diario"
@ -420,8 +430,7 @@ msgstr "Última actualización en"
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form #: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_form #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_form
msgid "Legend (for the markers inside invoice lines description)" msgid "Legend (for the markers inside invoice lines description)"
msgstr ""
"Leyenda (para los marcadores dentro de descripción en lineas de factura)"
msgstr "Leyenda (para los marcadores dentro de descripción en lineas de factura)"
#. module: contract #. module: contract
#: selection:account.analytic.account,recurring_rule_type:0 #: selection:account.analytic.account,recurring_rule_type:0
@ -450,6 +459,11 @@ msgstr "Próxima factura"
msgid "Partner" msgid "Partner"
msgstr "Empresa" msgstr "Empresa"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_partner_id
msgid "Partner (always False)"
msgstr "Empresa (siempre Falso)"
#. module: contract #. module: contract
#: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search #: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search
msgid "Partner and dependents" msgid "Partner and dependents"
@ -476,6 +490,7 @@ msgstr "Prepago"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_pricelist_id #: model:ir.model.fields,field_description:contract.field_account_analytic_account_pricelist_id
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_pricelist_id #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_pricelist_id
#: model:ir.model.fields,field_description:contract.field_project_project_pricelist_id
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search
msgid "Pricelist" msgid "Pricelist"
msgstr "Lista de precios" msgstr "Lista de precios"
@ -495,6 +510,7 @@ msgstr "Cantidad"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_rule_type #: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_rule_type
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_rule_type #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_rule_type
#: model:ir.model.fields,field_description:contract.field_project_project_recurring_rule_type
#: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search #: model:ir.ui.view,arch_db:contract.account_analytic_contract_view_search
msgid "Recurrence" msgid "Recurrence"
msgstr "Recurrencia" msgstr "Recurrencia"
@ -508,12 +524,14 @@ msgstr "Facturas recurrentes"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_interval #: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_interval
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_interval #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_recurring_interval
#: model:ir.model.fields,field_description:contract.field_project_project_recurring_interval
msgid "Repeat Every" msgid "Repeat Every"
msgstr "Repetir cada" msgstr "Repetir cada"
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_interval #: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_interval
#: model:ir.model.fields,help:contract.field_account_analytic_contract_recurring_interval #: model:ir.model.fields,help:contract.field_account_analytic_contract_recurring_interval
#: model:ir.model.fields,help:contract.field_project_project_recurring_interval
msgid "Repeat every (Days/Week/Month/Year)" msgid "Repeat every (Days/Week/Month/Year)"
msgstr "Repetir cada (días/semana/mes/año)" msgstr "Repetir cada (días/semana/mes/año)"
@ -544,18 +562,25 @@ msgstr "Secuencia de la linea de contrato cuando se muestra en los contratos"
msgid "Show the contracts for this partner" msgid "Show the contracts for this partner"
msgstr "Muestra los contratos para esta empresa/contacto" msgstr "Muestra los contratos para esta empresa/contacto"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_line_specific_price
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_specific_price
msgid "Specific Price"
msgstr "Precio específico"
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_rule_type #: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_rule_type
#: model:ir.model.fields,help:contract.field_account_analytic_contract_recurring_rule_type #: model:ir.model.fields,help:contract.field_account_analytic_contract_recurring_rule_type
#: model:ir.model.fields,help:contract.field_project_project_recurring_rule_type
msgid "Specify Interval for automatic invoice generation." msgid "Specify Interval for automatic invoice generation."
msgstr "Especifica el intervalo para la generación de facturas automática." msgstr "Especifica el intervalo para la generación de facturas automática."
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_invoicing_type #: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_invoicing_type
#: model:ir.model.fields,help:contract.field_account_analytic_contract_recurring_invoicing_type #: model:ir.model.fields,help:contract.field_account_analytic_contract_recurring_invoicing_type
#: model:ir.model.fields,help:contract.field_project_project_recurring_invoicing_type
msgid "Specify if process date is 'from' or 'to' invoicing date" msgid "Specify if process date is 'from' or 'to' invoicing date"
msgstr ""
"Especifica si la fecha de proceso es desde o hasta la fecha de facturación"
msgstr "Especifica si la fecha de proceso es desde o hasta la fecha de facturación"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_contract_line_price_subtotal #: model:ir.model.fields,field_description:contract.field_account_analytic_contract_line_price_subtotal
@ -600,11 +625,8 @@ msgstr "Año(s)"
#. module: contract #. module: contract
#: code:addons/contract/models/account_analytic_account.py:112 #: code:addons/contract/models/account_analytic_account.py:112
#, python-format #, python-format
msgid ""
"You can't have a next invoicing date before the start of the contract '%s'"
msgstr ""
"No puede tener una fecha de próxima factura anterior a la fecha de inicio "
"del contrato '%s'"
msgid "You can't have a next invoicing date before the start of the contract '%s'"
msgstr "No puede tener una fecha de próxima factura anterior a la fecha de inicio del contrato '%s'"
#. module: contract #. module: contract
#: code:addons/contract/models/account_analytic_account.py:217 #: code:addons/contract/models/account_analytic_account.py:217
@ -615,11 +637,9 @@ msgstr "¡Seleccione un cliente para este contrato %s!"
#. module: contract #. module: contract
#: code:addons/contract/models/account_analytic_account.py:274 #: code:addons/contract/models/account_analytic_account.py:274
#, python-format #, python-format
msgid ""
"You must review start and end dates!\n"
msgid "You must review start and end dates!\n"
"%s" "%s"
msgstr ""
"Debe revisar las fechas de inicio y de fin\n"
msgstr "Debe revisar las fechas de inicio y de fin\n"
"%s" "%s"
#. module: contract #. module: contract
@ -654,3 +674,4 @@ msgstr "account.analytic.invoice.line"
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form #: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "⇒ Show recurring invoices" msgid "⇒ Show recurring invoices"
msgstr "⇒ Mostrar facturas recurrentes" msgstr "⇒ Mostrar facturas recurrentes"

13
contract/migrations/10.0.4.0.0/pre-migration.py

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
def migrate(cr, version):
"""Rename column for specific price for keeping backwards compatibility."""
if not version:
return
cr.execute(
"ALTER TABLE account_analytic_invoice_line "
"RENAME price_unit TO specific_price"
)

14
contract/models/account_analytic_contract.py

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 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>
# Copyright 2004-2010 OpenERP SA
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016-2017 LasLabs Inc. # Copyright 2016-2017 LasLabs Inc.
# Copyright 2015-2017 Tecnativa - Pedro M. Baeza
# 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 odoo import api, fields, models from odoo import api, fields, models
@ -15,11 +15,17 @@ class AccountAnalyticContract(models.Model):
# These fields will not be synced to the contract # These fields will not be synced to the contract
NO_SYNC = [ NO_SYNC = [
'name', 'name',
'partner_id',
] ]
name = fields.Char( name = fields.Char(
required=True, required=True,
) )
# Needed for avoiding errors on several inherited behaviors
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Partner (always False)",
)
pricelist_id = fields.Many2one( pricelist_id = fields.Many2one(
comodel_name='product.pricelist', comodel_name='product.pricelist',
string='Pricelist', string='Pricelist',

55
contract/models/account_analytic_invoice_line.py

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 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>
# Copyright 2004-2010 OpenERP SA
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
# Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2016-2017 LasLabs Inc. # Copyright 2016-2017 LasLabs Inc.
# Copyright 2015-2017 Tecnativa - Pedro M. Baeza
# 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 odoo import api, fields, models from odoo import api, fields, models
@ -40,9 +40,19 @@ class AccountAnalyticInvoiceLine(models.Model):
string='Unit of Measure', string='Unit of Measure',
required=True, required=True,
) )
automatic_price = fields.Boolean(
string="Auto-price?",
help="If this is marked, the price will be obtained automatically "
"applying the pricelist to the product. If not, you will be "
"able to introduce a manual price",
)
specific_price = fields.Float(
string='Specific Price',
)
price_unit = fields.Float( price_unit = fields.Float(
'Unit Price',
required=True,
string='Unit Price',
compute="_compute_price_unit",
inverse="_inverse_price_unit",
) )
price_subtotal = fields.Float( price_subtotal = fields.Float(
compute='_compute_price_subtotal', compute='_compute_price_subtotal',
@ -61,6 +71,35 @@ class AccountAnalyticInvoiceLine(models.Model):
help="Sequence of the contract line when displaying contracts", help="Sequence of the contract line when displaying contracts",
) )
@api.depends(
'automatic_price',
'specific_price',
'product_id',
'quantity',
'analytic_account_id.pricelist_id',
'analytic_account_id.partner_id',
)
def _compute_price_unit(self):
"""Get the specific price if no auto-price, and the price obtained
from the pricelist otherwise.
"""
for line in self:
if line.automatic_price:
product = line.product_id.with_context(
quantity=line.quantity,
pricelist=line.analytic_account_id.pricelist_id.id,
partner=line.analytic_account_id.partner_id.id,
date=line.env.context.get('old_date', fields.Date.today()),
)
line.price_unit = product.price
else:
line.price_unit = line.specific_price
def _inverse_price_unit(self):
"""Store the specific price in the no auto-price records."""
for line in self.filtered(lambda x: not x.automatic_price):
line.specific_price = self.price_unit
@api.multi @api.multi
@api.depends('quantity', 'price_unit', 'discount') @api.depends('quantity', 'price_unit', 'discount')
def _compute_price_subtotal(self): def _compute_price_subtotal(self):
@ -98,12 +137,12 @@ class AccountAnalyticInvoiceLine(models.Model):
if self.analytic_account_id._name == 'account.analytic.account': if self.analytic_account_id._name == 'account.analytic.account':
date = ( date = (
self.analytic_account_id.recurring_next_date or self.analytic_account_id.recurring_next_date or
fields.Datetime.now()
fields.Date.today()
) )
partner = self.analytic_account_id.partner_id partner = self.analytic_account_id.partner_id
else: else:
date = fields.Datetime.now()
date = fields.Date.today()
partner = self.env.user.partner_id partner = self.env.user.partner_id
product = self.product_id.with_context( product = self.product_id.with_context(

14
contract/tests/test_contract.py

@ -60,6 +60,20 @@ class TestContract(TestContractBase):
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
self.acct_line.write({'discount': 120}) self.acct_line.write({'discount': 120})
def test_automatic_price(self):
self.acct_line.automatic_price = True
self.product.list_price = 1100
self.assertEqual(self.acct_line.price_unit, 1100)
# Try to write other price
self.acct_line.price_unit = 10
self.acct_line.refresh()
self.assertEqual(self.acct_line.price_unit, 1100)
# Now disable automatic price
self.acct_line.automatic_price = False
self.acct_line.price_unit = 10
self.acct_line.refresh()
self.assertEqual(self.acct_line.price_unit, 10)
def test_contract(self): def test_contract(self):
self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0) self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0)
res = self.acct_line._onchange_product_id() res = self.acct_line._onchange_product_id()

4
contract/views/account_analytic_account_view.xml

@ -77,7 +77,9 @@
<field name="name"/> <field name="name"/>
<field name="quantity"/> <field name="quantity"/>
<field name="uom_id"/> <field name="uom_id"/>
<field name="price_unit"/>
<field name="automatic_price"/>
<field name="price_unit" attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field name="specific_price" invisible="1"/>
<field name="discount" groups="sale.group_discount_per_so_line" /> <field name="discount" groups="sale.group_discount_per_so_line" />
<field name="price_subtotal"/> <field name="price_subtotal"/>
</tree> </tree>

6
contract/views/account_analytic_contract_view.xml

@ -29,14 +29,16 @@
</group> </group>
</group> </group>
<group name="group_invoice_lines" string="Invoice Lines"> <group name="group_invoice_lines" string="Invoice Lines">
<field name="recurring_invoice_line_ids">
<field name="recurring_invoice_line_ids" nolabel="1">
<tree string="Account Analytic Lines" editable="bottom"> <tree string="Account Analytic Lines" editable="bottom">
<field name="sequence" widget="handle" /> <field name="sequence" widget="handle" />
<field name="product_id" /> <field name="product_id" />
<field name="name" /> <field name="name" />
<field name="quantity" /> <field name="quantity" />
<field name="uom_id" /> <field name="uom_id" />
<field name="price_unit" />
<field name="automatic_price"/>
<field name="price_unit" attrs="{'readonly': [('automatic_price', '=', True)]}"/>
<field name="specific_price" invisible="1"/>
<field name="discount" groups="sale.group_discount_per_so_line" /> <field name="discount" groups="sale.group_discount_per_so_line" />
<field name="price_subtotal" /> <field name="price_subtotal" />
</tree> </tree>

Loading…
Cancel
Save