[IMP] base, various: support batch creation

Done for res.partner.bank, res.company and board models. Some override may
have been ignored because heavily linked to business code (like company
in stock).

See merge commit for more details.

Task ID-2330149
COM PR odoo/odoo#61246
ENT PR odoo/enterprise#14561
This commit is contained in:
Victor Feyens
2020-12-03 10:18:36 +00:00
committed by Thibault Delavallée
parent 110e8dbd54
commit caeda18bec
6 changed files with 56 additions and 49 deletions
+10 -9
View File
@@ -67,15 +67,16 @@ class ResPartnerBank(models.Model):
raise UserError(_("Cannot compute the BBAN because the account number is not an IBAN."))
return get_bban_from_iban(self.acc_number)
@api.model
def create(self, vals):
if vals.get('acc_number'):
try:
validate_iban(vals['acc_number'])
vals['acc_number'] = pretty_iban(normalize_iban(vals['acc_number']))
except ValidationError:
pass
return super(ResPartnerBank, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get('acc_number'):
try:
validate_iban(vals['acc_number'])
vals['acc_number'] = pretty_iban(normalize_iban(vals['acc_number']))
except ValidationError:
pass
return super(ResPartnerBank, self).create(vals_list)
def write(self, vals):
if vals.get('acc_number'):
+2 -2
View File
@@ -9,8 +9,8 @@ class Board(models.AbstractModel):
_description = "Board"
_auto = False
@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
return self
@api.model
+9 -8
View File
@@ -23,14 +23,15 @@ class ResCompany(models.Model):
return False
return self.country_id and self.country_id.code in self._get_unalterable_country()
@api.model
def create(self, vals):
company = super(ResCompany, self).create(vals)
#when creating a new french company, create the securisation sequence as well
if company._is_accounting_unalterable():
sequence_fields = ['l10n_fr_closing_sequence_id']
company._create_secure_sequence(sequence_fields)
return company
@api.model_create_multi
def create(self, vals_list):
companies = super().create(vals_list)
for company in companies:
#when creating a new french company, create the securisation sequence as well
if company._is_accounting_unalterable():
sequence_fields = ['l10n_fr_closing_sequence_id']
company._create_secure_sequence(sequence_fields)
return companies
def write(self, vals):
res = super(ResCompany, self).write(vals)
@@ -26,14 +26,15 @@ class ResCompany(models.Model):
l10n_fr_pos_cert_sequence_id = fields.Many2one('ir.sequence')
@api.model
def create(self, vals):
company = super(ResCompany, self).create(vals)
#when creating a new french company, create the securisation sequence as well
if company._is_accounting_unalterable():
sequence_fields = ['l10n_fr_pos_cert_sequence_id']
company._create_secure_sequence(sequence_fields)
return company
@api.model_create_multi
def create(self, vals_list):
companies = super().create(vals_list)
for company in companies:
#when creating a new french company, create the securisation sequence as well
if company._is_accounting_unalterable():
sequence_fields = ['l10n_fr_pos_cert_sequence_id']
company._create_secure_sequence(sequence_fields)
return companies
def write(self, vals):
res = super(ResCompany, self).write(vals)
+21 -17
View File
@@ -7,24 +7,28 @@ from odoo import api, models, _
class ResCompany(models.Model):
_inherit = "res.company"
@api.model
def create(self, vals):
new_company = super(ResCompany, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
companies = super(ResCompany, self).create(vals_list)
ProductPricelist = self.env['product.pricelist']
pricelist = ProductPricelist.search([('currency_id', '=', new_company.currency_id.id), ('company_id', '=', False)], limit=1)
if not pricelist:
params = {'currency': new_company.currency_id.name}
pricelist = ProductPricelist.create({
'name': _("Default %(currency)s pricelist") % params,
'currency_id': new_company.currency_id.id,
})
self.env['ir.property']._set_default(
'property_product_pricelist',
'res.partner',
pricelist,
new_company,
)
return new_company
for new_company in companies:
pricelist = ProductPricelist.search([
('currency_id', '=', new_company.currency_id.id),
('company_id', '=', False)
], limit=1)
if not pricelist:
params = {'currency': new_company.currency_id.name}
pricelist = ProductPricelist.create({
'name': _("Default %(currency)s pricelist") % params,
'currency_id': new_company.currency_id.id,
})
self.env['ir.property']._set_default(
'property_product_pricelist',
'res.partner',
pricelist,
new_company,
)
return companies
def write(self, values):
# When we modify the currency of the company, we reflect the change on the list0 pricelist, if
+5 -5
View File
@@ -755,13 +755,13 @@ class Base(models.AbstractModel):
class ResCompany(models.Model):
_inherit = 'res.company'
@api.model
def create(self, values):
res = super().create(values)
@api.model_create_multi
def create(self, vals_list):
companies = super().create(vals_list)
style_fields = {'external_report_layout_id', 'font', 'primary_color', 'secondary_color'}
if not style_fields.isdisjoint(values):
if any(not style_fields.isdisjoint(values) for values in vals_list):
self._update_asset_style()
return res
return companies
def write(self, values):
res = super().write(values)