diff --git a/product_usability/models/__init__.py b/product_usability/models/__init__.py index 7ef8d55..ee1a5d5 100644 --- a/product_usability/models/__init__.py +++ b/product_usability/models/__init__.py @@ -1,4 +1,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import product +from . import product_template +from . import product_supplierinfo +from . import product_price_history from . import pricelist diff --git a/product_usability/models/product.py b/product_usability/models/product.py index 5a95211..c502ec4 100644 --- a/product_usability/models/product.py +++ b/product_usability/models/product.py @@ -1,41 +1,31 @@ - +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# @author Raphaël Valyi # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields -class ProductTemplate(models.Model): - _inherit = 'product.template' - - name = fields.Char(track_visibility='onchange') - type = fields.Selection(track_visibility='onchange') - categ_id = fields.Many2one(track_visibility='onchange') - list_price = fields.Float(track_visibility='onchange') - sale_ok = fields.Boolean(track_visibility='onchange') - purchase_ok = fields.Boolean(track_visibility='onchange') - active = fields.Boolean(track_visibility='onchange') - - def show_product_price_history(self): - self.ensure_one() - products = self.env['product.product'].search( - [('product_tmpl_id', '=', self._context['active_id'])]) - action = self.env['ir.actions.act_window'].for_xml_id( - 'product_usability', 'product_price_history_action') - action.update({ - 'domain': "[('product_id', 'in', %s)]" % products.ids, - }) - return action - - class ProductProduct(models.Model): _inherit = 'product.product' - default_code = fields.Char(track_visibility='onchange', copy=False) - barcode = fields.Char(track_visibility='onchange', copy=False) - weight = fields.Float(track_visibility='onchange') - active = fields.Boolean(track_visibility='onchange') + default_code = fields.Char( + track_visibility='onchange', + copy=False) + + barcode = fields.Char( + track_visibility='onchange', + copy=False) + + weight = fields.Float( + track_visibility='onchange') + + active = fields.Boolean( + track_visibility='onchange') + price_history_ids = fields.One2many( - 'product.price.history', 'product_id', + comodel_name='product.price.history', + inverse_name='product_id', string='Product Price History') _sql_constraints = [( @@ -50,24 +40,9 @@ class ProductProduct(models.Model): def show_product_price_history(self): self.ensure_one() - action = self.env['ir.actions.act_window'].for_xml_id( + action = self.env.ref(['ir.actions.act_window'].for_xml_id( 'product_usability', 'product_price_history_action') action.update({ 'domain': "[('product_id', '=', %d)]" % self.ids[0], }) return action - - -class ProductSupplierinfo(models.Model): - _inherit = 'product.supplierinfo' - - name = fields.Many2one( - domain=[('supplier', '=', True), ('parent_id', '=', False)]) - - -class ProductPriceHistory(models.Model): - _inherit = 'product.price.history' - - company_currency_id = fields.Many2one( - related='company_id.currency_id', readonly=True, compute_sudo=True, - string='Company Currency') diff --git a/product_usability/models/product_price_history.py b/product_usability/models/product_price_history.py new file mode 100644 index 0000000..af7b390 --- /dev/null +++ b/product_usability/models/product_price_history.py @@ -0,0 +1,16 @@ +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# @author Raphaël Valyi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class ProductPriceHistory(models.Model): + _inherit = 'product.price.history' + + company_currency_id = fields.Many2one( + related='company_id.currency_id', + readonly=True, + compute_sudo=True, + string='Company Currency') diff --git a/product_usability/models/product_supplierinfo.py b/product_usability/models/product_supplierinfo.py new file mode 100644 index 0000000..2526eab --- /dev/null +++ b/product_usability/models/product_supplierinfo.py @@ -0,0 +1,13 @@ +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# @author Raphaël Valyi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class ProductSupplierinfo(models.Model): + _inherit = 'product.supplierinfo' + + name = fields.Many2one( + domain=[('supplier', '=', True), ('parent_id', '=', False)]) diff --git a/product_usability/models/product_template.py b/product_usability/models/product_template.py new file mode 100644 index 0000000..1e7344e --- /dev/null +++ b/product_usability/models/product_template.py @@ -0,0 +1,42 @@ +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# @author Raphaël Valyi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + name = fields.Char( + track_visibility='onchange') + + type = fields.Selection( + track_visibility='onchange') + + categ_id = fields.Many2one( + track_visibility='onchange') + + list_price = fields.Float( + track_visibility='onchange') + + sale_ok = fields.Boolean( + track_visibility='onchange') + + purchase_ok = fields.Boolean( + track_visibility='onchange') + + active = fields.Boolean( + track_visibility='onchange') + + def show_product_price_history(self): + self.ensure_one() + products = self.env['product.product'].search( + [('product_tmpl_id', '=', self._context['active_id'])]) + action = self.env['ir.actions.act_window'].for_xml_id( + 'product_usability', 'product_price_history_action') + action.update({ + 'domain': "[('product_id', 'in', %s)]" % products.ids, + }) + return action