diff --git a/addons/purchase/__openerp__.py b/addons/purchase/__openerp__.py index 2e018de9958..5c16cac93c8 100644 --- a/addons/purchase/__openerp__.py +++ b/addons/purchase/__openerp__.py @@ -4,7 +4,7 @@ { 'name': 'Purchase Management', - 'version': '1.1', + 'version': '1.2', 'category': 'Purchase Management', 'sequence': 60, 'summary': 'Purchase Orders, Receipts, Vendor Bills', diff --git a/addons/purchase/migrations/9.0.1.2/pre-create-properties.py b/addons/purchase/migrations/9.0.1.2/pre-create-properties.py new file mode 100644 index 00000000000..e9d3b0606d8 --- /dev/null +++ b/addons/purchase/migrations/9.0.1.2/pre-create-properties.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +def convert_field(cr, model, field, target_model): + table = model.replace('.', '_') + + cr.execute("""SELECT 1 + FROM information_schema.columns + WHERE table_name = %s + AND column_name = %s + """, (table, field)) + if not cr.fetchone(): + return + + cr.execute("SELECT id FROM ir_model_fields WHERE model=%s AND name=%s", (model, field)) + [fields_id] = cr.fetchone() + + cr.execute(""" + INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference) + SELECT %(field)s, 'many2one', %(fields_id)s, company_id, CONCAT('{model},', id), + CONCAT('{target_model},', {field}) + FROM {table} t + WHERE {field} IS NOT NULL + AND NOT EXISTS(SELECT 1 + FROM ir_property + WHERE fields_id=%(fields_id)s + AND company_id=t.company_id + AND res_id=CONCAT('{model},', t.id)) + """.format(**locals()), locals()) + + cr.execute('ALTER TABLE "{0}" DROP COLUMN "{1}" CASCADE'.format(table, field)) + +def migrate(cr, version): + convert_field(cr, 'res.partner', 'property_purchase_currency_id', 'res.currency') + convert_field(cr, 'product.template', + 'property_account_creditor_price_difference', 'account.account') diff --git a/addons/purchase/partner.py b/addons/purchase/partner.py index 9b71ff824b0..cbdb5c114f4 100644 --- a/addons/purchase/partner.py +++ b/addons/purchase/partner.py @@ -19,7 +19,8 @@ class res_partner(models.Model): def _commercial_fields(self): return super(res_partner, self)._commercial_fields() - property_purchase_currency_id = fields.Many2one('res.currency', string="Supplier Currency",\ - help="This currency will be used, instead of the default one, for purchases from the current partner") + property_purchase_currency_id = fields.Many2one( + 'res.currency', string="Supplier Currency", company_dependent=True, + help="This currency will be used, instead of the default one, for purchases from the current partner") purchase_order_count = fields.Integer(compute='_purchase_invoice_count', string='# of Purchase Order') supplier_invoice_count = fields.Integer(compute='_purchase_invoice_count', string='# Vendor Bills') diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index d351363ef7c..8f01ecce86f 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -822,7 +822,8 @@ class ProductTemplate(models.Model): template.purchase_count = sum([p.purchase_count for p in template.product_variant_ids]) return True - property_account_creditor_price_difference = fields.Many2one('account.account', string="Price Difference Account",\ + property_account_creditor_price_difference = fields.Many2one( + 'account.account', string="Price Difference Account", company_dependent=True, help="This account will be used to value price difference between purchase price and cost price.") purchase_ok = fields.Boolean('Can be Purchased', default=True) purchase_count = fields.Integer(compute='_purchase_count', string='# Purchases')