diff --git a/agreement/models/__init__.py b/agreement/models/__init__.py index 54733bfb..bd041e54 100644 --- a/agreement/models/__init__.py +++ b/agreement/models/__init__.py @@ -6,6 +6,7 @@ from . import ( agreement, agreement_appendix, agreement_clause, + agreement_line, agreement_recital, agreement_section, agreement_serviceprofile, diff --git a/agreement/models/agreement.py b/agreement/models/agreement.py index ff8c6731..93d1df38 100644 --- a/agreement/models/agreement.py +++ b/agreement/models/agreement.py @@ -279,8 +279,7 @@ class Agreement(models.Model): string="Appendices", copy=True) serviceprofile_ids = fields.One2many('agreement.serviceprofile', 'agreement_id', - string="Service Profiles", - readonly=True) + string="Service Profiles") analytic_id = fields.Many2one('account.analytic.account', string='Analytic Account', index=True) analytic_line_ids = fields.One2many('account.analytic.line', @@ -301,11 +300,8 @@ class Agreement(models.Model): copy=False, domain=[('active', '=', True)] ) - products_ids = fields.Many2many( - 'product.template', - string="Products", - copy=False - ) + line_ids = fields.One2many('agreement.line', 'agreement_id', + string="Products/Services", copy=False) state = fields.Selection([ ('draft', 'Draft'), ('active', 'Active'), diff --git a/agreement/models/agreement_line.py b/agreement/models/agreement_line.py new file mode 100644 index 00000000..52868bf3 --- /dev/null +++ b/agreement/models/agreement_line.py @@ -0,0 +1,22 @@ +# Copyright (C) 2018 - TODAY, Pavlov Media +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AgreementLine(models.Model): + _name = 'agreement.line' + _description = 'Agreement Lines' + + product_id = fields.Many2one('product.product', string='Product') + name = fields.Char(string="Description", required=True) + agreement_id = fields.Many2one('agreement', string="Agreement", + ondelete="cascade") + qty = fields.Float(string='Quantity') + uom_id = fields.Many2one('product.uom', string='Unit of Measure', + required=True) + + @api.onchange('product_id') + def _onchange_product_id(self): + self.name = self.product_id.name + self.uom_id = self.product_id.uom_id.id diff --git a/agreement/views/agreement.xml b/agreement/views/agreement.xml index 4ae4f9ba..76f391ee 100644 --- a/agreement/views/agreement.xml +++ b/agreement/views/agreement.xml @@ -66,8 +66,8 @@
For dynamic content use mako expression '${expression}'. For ex: - 1. object's field name: ${object.field_name} or - 2. many2one field name: ${object.many2one_field_id.field_name} + 1. object's field name: ${object.field_name} or + 2. many2one field name: ${object.many2one_field_id.field_name}