diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index d1dc37ee..aa0f3b74 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -10,7 +10,11 @@ 'author': "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", 'website': 'https://github.com/oca/contract', 'depends': ['product', 'contract_sale'], - 'data': ['views/product_template.xml', 'views/sale_order.xml'], + 'data': [ + 'views/contract.xml', + 'views/product_template.xml', + 'views/sale_order.xml' + ], 'installable': True, 'application': False, } diff --git a/product_contract/models/__init__.py b/product_contract/models/__init__.py index a275fa21..6ec5fa03 100644 --- a/product_contract/models/__init__.py +++ b/product_contract/models/__init__.py @@ -2,6 +2,7 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import contract from . import contract_line from . import product_template from . import sale_order diff --git a/product_contract/models/contract.py b/product_contract/models/contract.py new file mode 100644 index 00000000..56279cef --- /dev/null +++ b/product_contract/models/contract.py @@ -0,0 +1,35 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.tools.translate import _ + + +class AccountAnalyticAccount(models.Model): + _name = 'account.analytic.account' + _inherit = 'account.analytic.account' + + sale_order_count = fields.Integer(compute="_compute_sale_order_count") + + @api.depends('recurring_invoice_line_ids') + def _compute_sale_order_count(self): + for rec in self: + rec.sale_order_count = len( + rec.recurring_invoice_line_ids.mapped( + 'sale_order_line_id.order_id' + ) + ) + + @api.multi + def action_view_sales_orders(self): + self.ensure_one() + orders = self.recurring_invoice_line_ids.mapped( + 'sale_order_line_id.order_id' + ) + return { + "name": _("Sales Orders"), + "view_mode": "tree,form", + "res_model": "sale.order", + "type": "ir.actions.act_window", + "domain": [("id", "in", orders.ids)], + } diff --git a/product_contract/views/contract.xml b/product_contract/views/contract.xml new file mode 100644 index 00000000..abf53e6e --- /dev/null +++ b/product_contract/views/contract.xml @@ -0,0 +1,29 @@ + + + + + + account.analytic.account + + + + + + + + +