diff --git a/product_usability/__init__.py b/product_usability/__init__.py index fe50f8f..69f7bab 100644 --- a/product_usability/__init__.py +++ b/product_usability/__init__.py @@ -1,3 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import product -from . import pricelist +from . import models diff --git a/product_usability/__manifest__.py b/product_usability/__manifest__.py index f37703c..46cd262 100644 --- a/product_usability/__manifest__.py +++ b/product_usability/__manifest__.py @@ -28,7 +28,11 @@ This module has been written by Alexis de Lattre from Akretion +# @author Raphaël Valyi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields +from odoo.tools.safe_eval import safe_eval + + +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') + + price_history_ids = fields.One2many( + comodel_name='product.price.history', + inverse_name='product_id', + string='Product Price History') + + _sql_constraints = [( + # Maybe it could be better to have a constrain per company + # but the company_id field is on product.template, + # not on product.product + # If it's a problem, we'll create a company_id field on + # product.product + 'default_code_uniq', + 'unique(default_code)', + 'This internal reference already exists!')] + + def show_product_price_history(self): + self.ensure_one() + action = self.env.ref( + 'product_usability.product_price_history_action').read()[0] + action['domain'] = safe_eval(action['domain']) + action['domain'].append(('product_id', '=', self.id)) + return action 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..c1d1d66 --- /dev/null +++ b/product_usability/models/product_template.py @@ -0,0 +1,40 @@ +# © 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.ref( + 'product_usability.product_price_history_action').read()[0] + action['domain'] = [('product_id', 'in', products.ids)] + return action diff --git a/product_usability/product.py b/product_usability/product.py deleted file mode 100644 index 5a95211..0000000 --- a/product_usability/product.py +++ /dev/null @@ -1,73 +0,0 @@ - -# 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') - price_history_ids = fields.One2many( - 'product.price.history', 'product_id', - string='Product Price History') - - _sql_constraints = [( - # Maybe it could be better to have a constrain per company - # but the company_id field is on product.template, - # not on product.product - # If it's a problem, we'll create a company_id field on - # product.product - 'default_code_uniq', - 'unique(default_code)', - 'This internal reference already exists!')] - - def show_product_price_history(self): - self.ensure_one() - action = self.env['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/product_view.xml b/product_usability/product_view.xml deleted file mode 100644 index a25c889..0000000 --- a/product_usability/product_view.xml +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - - product.price.history.form - product.price.history - -
- - - - - - - - -
-
-
- - - product.price.history.tree - product.price.history - - - - - - - - - - - - - - product.price.history.search - product.price.history - - - - - - - - - - - - - - Product Price History - product.price.history - tree,form - {'product_price_history_main_view': True} - - - - - - - usability.product.template.form - product.template - - - -