[FIX] purchase: enforce company dependent fields
During new-api rewrite, some property fields wrongly lost their company_dependent flag. Despite it need a migration script to create the missing properties, not updating the module does not lead to crashes.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
{
|
||||
'name': 'Purchase Management',
|
||||
'version': '1.1',
|
||||
'version': '1.2',
|
||||
'category': 'Purchase Management',
|
||||
'sequence': 60,
|
||||
'summary': 'Purchase Orders, Receipts, Vendor Bills',
|
||||
|
||||
@@ -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')
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user