[IMP] *: make ir.property methods private

Should only interact with them via python code in a controlled
environment, no direct call with RPC
This commit is contained in:
Martin Trigaux
2020-05-26 15:50:11 +02:00
parent 8f57863707
commit 4afa747fa1
16 changed files with 41 additions and 41 deletions
+5 -5
View File
@@ -213,11 +213,11 @@ class AccountTestCommon(SavepointCase):
# Properties: Product income and expense accounts, default parameters
Property = cls.env['ir.property']
Property.set_default('property_account_receivable_id', 'res.partner', cls.a_recv, cls.company)
Property.set_default('property_account_payable_id', 'res.partner', cls.a_pay, cls.company)
Property.set_default('property_account_position_id', 'res.partner', False, cls.company)
Property.set_default('property_account_expense_categ_id', 'product.category', cls.a_expense, cls.company)
Property.set_default('property_account_income_categ_id', 'product.category', cls.a_sale, cls.company)
Property._set_default('property_account_receivable_id', 'res.partner', cls.a_recv, cls.company)
Property._set_default('property_account_payable_id', 'res.partner', cls.a_pay, cls.company)
Property._set_default('property_account_position_id', 'res.partner', False, cls.company)
Property._set_default('property_account_expense_categ_id', 'product.category', cls.a_expense, cls.company)
Property._set_default('property_account_income_categ_id', 'product.category', cls.a_sale, cls.company)
# Bank Accounts
cls.bank_account = cls.env['res.partner.bank'].create({
+2 -2
View File
@@ -26,7 +26,7 @@ class HrExpense(models.Model):
@api.model
def _default_account_id(self):
return self.env['ir.property'].get('property_account_expense_categ_id', 'product.category')
return self.env['ir.property']._get('property_account_expense_categ_id', 'product.category')
@api.model
def _get_employee_id_domain(self):
@@ -365,7 +365,7 @@ class HrExpense(models.Model):
raise UserError(
_("No Expense account found for the product %s (or for its category), please configure one.") % (self.product_id.name))
else:
account = self.env['ir.property'].with_company(self.company_id).get('property_account_expense_categ_id', 'product.category')
account = self.env['ir.property'].with_company(self.company_id)._get('property_account_expense_categ_id', 'product.category')
if not account:
raise UserError(_('Please configure Default Expense account for Product expense: `property_account_expense_categ_id`.'))
return account
+1 -1
View File
@@ -30,7 +30,7 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'reconcile': True})
self.env.company.account_default_pos_receivable_account_id = account_receivable
self.env['ir.property'].set_default(
self.env['ir.property']._set_default(
'property_account_receivable_id',
'res.partner',
account_receivable,
+1 -1
View File
@@ -86,7 +86,7 @@ class TestFrontend(odoo.tests.HttpCase):
'user_type_id': self.env.ref('account.data_account_type_receivable').id,
'reconcile': True})
self.env['ir.property'].set_default(
self.env['ir.property']._set_default(
'property_account_receivable_id',
'res.partner',
account_receivable,
+2 -2
View File
@@ -340,7 +340,7 @@ class Pricelist(models.Model):
pl_domain = self._get_partner_pricelist_multi_search_domain_hook(company_id)
# if no specific property, try to find a fitting pricelist
result = Property.get_multi('property_product_pricelist', Partner._name, partner_ids)
result = Property._get_multi('property_product_pricelist', Partner._name, partner_ids)
remaining_partner_ids = [pid for pid, val in result.items() if not val or
not val._get_partner_pricelist_multi_filter_hook()]
@@ -348,7 +348,7 @@ class Pricelist(models.Model):
# get fallback pricelist when no pricelist for a given country
pl_fallback = (
Pricelist.search(pl_domain + [('country_group_ids', '=', False)], limit=1) or
Property.get('property_product_pricelist', 'res.partner') or
Property._get('property_product_pricelist', 'res.partner') or
Pricelist.search(pl_domain, limit=1)
)
# group partners by country, and find a pricelist for each country
+2 -2
View File
@@ -18,7 +18,7 @@ class ResCompany(models.Model):
'name': _("Default %(currency)s pricelist") % params,
'currency_id': new_company.currency_id.id,
})
self.env['ir.property'].sudo().set_default(
self.env['ir.property'].sudo()._set_default(
'property_product_pricelist',
'res.partner',
pricelist,
@@ -54,7 +54,7 @@ class ResCompany(models.Model):
'name': _("Default %(currency)s pricelist") % params,
'currency_id': currency_id,
})
self.env['ir.property'].sudo().set_default(
self.env['ir.property'].sudo()._set_default(
'property_product_pricelist',
'res.partner',
pricelist,
+2 -2
View File
@@ -29,11 +29,11 @@ class Partner(models.Model):
limit=1
)
default_for_country = pls and pls[0]
actual = self.env['ir.property'].get('property_product_pricelist', 'res.partner', 'res.partner,%s' % partner.id)
actual = self.env['ir.property']._get('property_product_pricelist', 'res.partner', 'res.partner,%s' % partner.id)
# update at each change country, and so erase old pricelist
if partner.property_product_pricelist or (actual and default_for_country and default_for_country.id != actual.id):
# keep the company of the current user before sudo
self.env['ir.property'].sudo().set_multi(
self.env['ir.property'].sudo()._set_multi(
'property_product_pricelist',
partner._name,
{partner.id: partner.property_product_pricelist or default_for_country.id},
+2 -2
View File
@@ -34,7 +34,7 @@ def _configure_journals(cr, registry):
'company_id': company_id.id,
'show_on_dashboard': False
}).id
env['ir.property'].set_default(
env['ir.property']._set_default(
'property_stock_journal',
'product.category',
journal_id,
@@ -51,7 +51,7 @@ def _configure_journals(cr, registry):
for name in todo_list:
account = getattr(company_id, name)
if account:
env['ir.property'].set_default(
env['ir.property']._set_default(
name,
'product.category',
account,
+2 -2
View File
@@ -11,13 +11,13 @@ class StockAccountTestCommon(AccountTestCommon):
super(StockAccountTestCommon, cls).setUpClass()
# Properties: Stock valuation account and journal
cls.env['ir.property'].set_default(
cls.env['ir.property']._set_default(
'property_stock_valuation_account_id',
'product.category',
cls.stk,
cls.env.company,
)
cls.env['ir.property'].set_default(
cls.env['ir.property']._set_default(
'property_stock_journal',
'product.category',
cls.miscellaneous_journal,
@@ -41,8 +41,8 @@ class TestUi(TestUICommon):
})
Property = self.env['ir.property']
Property.set_default('property_account_receivable_id', 'res.partner', a_recv, self.env.company)
Property.set_default('property_account_payable_id', 'res.partner', a_pay, self.env.company)
Property._set_default('property_account_receivable_id', 'res.partner', a_recv, self.env.company)
Property._set_default('property_account_payable_id', 'res.partner', a_pay, self.env.company)
product_course_channel_6 = self.env['product.product'].create({
'name': 'DIY Furniture Course',
+6 -6
View File
@@ -176,7 +176,7 @@ class Property(models.Model):
return False
@api.model
def set_default(self, name, model, value, company=False):
def _set_default(self, name, model, value, company=False):
""" Set the given field's generic value for the given company.
:param name: the field's name
@@ -204,7 +204,7 @@ class Property(models.Model):
})
@api.model
def get(self, name, model, res_id=False):
def _get(self, name, model, res_id=False):
""" Get the given field's generic value for the record.
:param name: the field's name
@@ -223,7 +223,7 @@ class Property(models.Model):
return p.get_by_record()
return False
# only cache Property.get(res_id=False) as that's
# only cache Property._get(res_id=False) as that's
# sub-optimally.
COMPANY_KEY = "self.env.company.id"
@ormcache(COMPANY_KEY, 'name', 'model')
@@ -255,7 +255,7 @@ class Property(models.Model):
return [('fields_id', '=', res[0]), ('company_id', 'in', [company_id, False])]
@api.model
def get_multi(self, name, model, ids):
def _get_multi(self, name, model, ids):
""" Read the property field `name` for the records of model `model` with
the given `ids`, and return a dictionary mapping `ids` to their
corresponding value.
@@ -319,7 +319,7 @@ class Property(models.Model):
}
@api.model
def set_multi(self, name, model, values, default_value=None):
def _set_multi(self, name, model, values, default_value=None):
""" Assign the property field `name` for the records of model `model`
with `values` (dictionary mapping record ids to their value).
If the value for a given record is the same as the default
@@ -340,7 +340,7 @@ class Property(models.Model):
if domain is None:
raise Exception()
# retrieve the default value for the field
default_value = clean(self.get(name, model))
default_value = clean(self._get(name, model))
# retrieve the properties corresponding to the given record ids
self._cr.execute("SELECT id FROM ir_model_fields WHERE name=%s AND model=%s", (name, model))
@@ -37,11 +37,11 @@ class BaseTestUi(odoo.tests.HttpCase):
})
Property = self.env['ir.property']
Property.set_default('property_account_receivable_id', 'res.partner', a_recv, self.env.company)
Property.set_default('property_account_payable_id', 'res.partner', a_pay, self.env.company)
Property.set_default('property_account_position_id', 'res.partner', False, self.env.company)
Property.set_default('property_account_expense_categ_id', 'product.category', a_expense, self.env.company)
Property.set_default('property_account_income_categ_id', 'product.category', a_sale, self.env.company)
Property._set_default('property_account_receivable_id', 'res.partner', a_recv, self.env.company)
Property._set_default('property_account_payable_id', 'res.partner', a_pay, self.env.company)
Property._set_default('property_account_position_id', 'res.partner', False, self.env.company)
Property._set_default('property_account_expense_categ_id', 'product.category', a_expense, self.env.company)
Property._set_default('property_account_income_categ_id', 'product.category', a_sale, self.env.company)
self.expenses_journal = self.env['account.journal'].create({
'name': 'Vendor Bills - Test',
@@ -1071,9 +1071,9 @@ class TestFields(TransactionCaseWithUserDemo):
tag2 = self.env['test_new_api.multi.tag'].create({'name': 'Quuz'})
# create default values for the company-dependent fields
self.env['ir.property'].set_default('foo', 'test_new_api.company', 'default')
self.env['ir.property'].set_default('foo', 'test_new_api.company', 'default1', company1)
self.env['ir.property'].set_default('tag_id', 'test_new_api.company', tag0)
self.env['ir.property']._set_default('foo', 'test_new_api.company', 'default')
self.env['ir.property']._set_default('foo', 'test_new_api.company', 'default1', company1)
self.env['ir.property']._set_default('tag_id', 'test_new_api.company', tag0)
# assumption: users don't have access to 'ir.property'
accesses = self.env['ir.model.access'].search([('model_id.model', '=', 'ir.property')])
@@ -459,7 +459,7 @@ class TestIrPropertyOptimizations(TransactionCase):
self.Eggs = self.env['test_performance.eggs']
def test_with_falsy_default(self):
self.assertFalse(self.env['ir.property'].get('property_eggs', 'test_performance.bacon'))
self.assertFalse(self.env['ir.property']._get('property_eggs', 'test_performance.bacon'))
# warmup
eggs = self.Eggs.create({})
@@ -492,7 +492,7 @@ class TestIrPropertyOptimizations(TransactionCase):
'value': eggs,
})
self.assertEqual(eggs, self.env['ir.property'].get('property_eggs', 'test_performance.bacon'))
self.assertEqual(eggs, self.env['ir.property']._get('property_eggs', 'test_performance.bacon'))
# warmup
self.Bacon.create({})
+3 -3
View File
@@ -571,12 +571,12 @@ class Field(MetaField('DummyField', (object,), {})):
#
def _default_company_dependent(self, model):
return model.env['ir.property'].get(self.name, self.model_name)
return model.env['ir.property']._get(self.name, self.model_name)
def _compute_company_dependent(self, records):
# read property as superuser, as the current user may not have access
Property = records.env['ir.property'].sudo()
values = Property.get_multi(self.name, self.model_name, records.ids)
values = Property._get_multi(self.name, self.model_name, records.ids)
for record in records:
record[self.name] = values.get(record.id)
@@ -587,7 +587,7 @@ class Field(MetaField('DummyField', (object,), {})):
record.id: self.convert_to_write(record[self.name], record)
for record in records
}
Property.set_multi(self.name, self.model_name, values)
Property._set_multi(self.name, self.model_name, values)
def _search_company_dependent(self, records, operator, value):
Property = records.env['ir.property']
+1 -1
View File
@@ -3705,7 +3705,7 @@ Record ids: %(records)s
if not field:
raise ValueError("Invalid field %r on model %r" % (key, self._name))
if field.company_dependent:
irprop_def = self.env['ir.property'].get(key, self._name)
irprop_def = self.env['ir.property']._get(key, self._name)
cached_def = field.convert_to_cache(irprop_def, self)
cached_val = field.convert_to_cache(val, self)
if cached_val == cached_def: