summaryrefslogtreecommitdiff
path: root/addons/account/models/account.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/account/models/account.py')
-rw-r--r--addons/account/models/account.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/addons/account/models/account.py b/addons/account/models/account.py
index 526a9ac2eaf..e2301af91d3 100644
--- a/addons/account/models/account.py
+++ b/addons/account/models/account.py
@@ -211,6 +211,7 @@ class AccountAccount(models.Model):
help="Forces all moves for this account to have this account currency.")
code = fields.Char(size=64, required=True, index=True)
deprecated = fields.Boolean(index=True, default=False)
+ used = fields.Boolean(store=False, search='_search_used')
user_type_id = fields.Many2one('account.account.type', string='Type', required=True,
help="Account Type is used for information purpose, to generate country-specific legal reports, and set the rules to close a fiscal year and generate opening entries.")
internal_type = fields.Selection(related='user_type_id.type', string="Internal Type", store=True, readonly=True)
@@ -252,6 +253,17 @@ class AccountAccount(models.Model):
for record in self:
record.root_id = record.code and (ord(record.code[0]) * 1000 + ord(record.code[1])) or False
+ def _search_used(self, operator, value):
+ if operator not in ['=', '!='] or not isinstance(value, bool):
+ raise UserError(_('Operation not supported'))
+ if operator != '=':
+ value = not value
+ self._cr.execute("""
+ SELECT id FROM account_account account
+ WHERE EXISTS (SELECT * FROM account_move_line aml WHERE aml.account_id = account.id LIMIT 1)
+ """)
+ return [('id', 'in' if value else 'not in', [r[0] for r in self._cr.fetchall()])]
+
@api.model
def _search_new_account_code(self, company, digits, prefix):
for num in range(1, 10000):
@@ -305,13 +317,13 @@ class AccountAccount(models.Model):
if opening_move_line:
if amount:
# modify the line
- setattr(opening_move_line.with_context({'check_move_validity': False}), field, amount)
+ opening_move_line.with_context(check_move_validity=False)[field] = amount
elif counter_part_map[field]:
# delete the line (no need to keep a line with value = 0)
- opening_move_line.with_context({'check_move_validity': False}).unlink()
+ opening_move_line.with_context(check_move_validity=False).unlink()
elif amount:
# create a new line, as none existed before
- self.env['account.move.line'].with_context({'check_move_validity': False}).create({
+ self.env['account.move.line'].with_context(check_move_validity=False).create({
'name': _('Opening balance'),
field: amount,
'move_id': opening_move.id,
@@ -349,7 +361,7 @@ class AccountAccount(models.Model):
if operator in expression.NEGATIVE_TERM_OPERATORS:
domain = ['&', '!'] + domain[1:]
account_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return self.browse(account_ids).name_get()
+ return models.lazy_name_get(self.browse(account_ids).with_user(name_get_uid))
@api.onchange('user_type_id')
def _onchange_user_type_id(self):
@@ -550,7 +562,7 @@ class AccountGroup(models.Model):
criteria_operator = ['|'] if operator not in expression.NEGATIVE_TERM_OPERATORS else ['&', '!']
domain = criteria_operator + [('code_prefix', '=ilike', name + '%'), ('name', operator, name)]
group_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return self.browse(group_ids).name_get()
+ return models.lazy_name_get(self.browse(group_ids).with_user(name_get_uid))
class AccountRoot(models.Model):
@@ -560,6 +572,7 @@ class AccountRoot(models.Model):
name = fields.Char()
parent_id = fields.Many2one('account.root')
+ company_id = fields.Many2one('res.company')
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -567,12 +580,14 @@ class AccountRoot(models.Model):
CREATE OR REPLACE VIEW %s AS (
SELECT DISTINCT ASCII(code) * 1000 + ASCII(SUBSTRING(code,2,1)) AS id,
LEFT(code,2) AS name,
- ASCII(code) AS parent_id
+ ASCII(code) AS parent_id,
+ company_id
FROM account_account WHERE code IS NOT NULL
UNION ALL
SELECT DISTINCT ASCII(code) AS id,
LEFT(code,1) AS name,
- NULL::int AS parent_id
+ NULL::int AS parent_id,
+ company_id
FROM account_account WHERE code IS NOT NULL
)''' % (self._table,)
)
@@ -777,9 +792,9 @@ class AccountJournal(models.Model):
if self.company_id != self.env.ref('base.main_company'):
alias_name += '-' + str(self.company_id.name)
return {
- 'alias_defaults': {'type': type == 'purchase' and 'in_invoice' or 'out_invoice', 'company_id': self.company_id.id},
+ 'alias_defaults': {'type': type == 'purchase' and 'in_invoice' or 'out_invoice', 'company_id': self.company_id.id, 'journal_id': self.id},
'alias_parent_thread_id': self.id,
- 'alias_name': re.sub(r'[^\w]+', '-', alias_name)
+ 'alias_name': alias_name,
}
def unlink(self):
@@ -1019,7 +1034,7 @@ class AccountJournal(models.Model):
connector = '&' if operator in expression.NEGATIVE_TERM_OPERATORS else '|'
domain = [connector, ('code', operator, name), ('name', operator, name)]
journal_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return self.browse(journal_ids).name_get()
+ return models.lazy_name_get(self.browse(journal_ids).with_user(name_get_uid))
@api.depends('inbound_payment_method_ids', 'outbound_payment_method_ids')
def _methods_compute(self):
@@ -1233,7 +1248,7 @@ class AccountTax(models.Model):
connector = '&' if operator in expression.NEGATIVE_TERM_OPERATORS else '|'
domain = [connector, ('description', operator, name), ('name', operator, name)]
tax_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
- return self.browse(tax_ids).name_get()
+ return models.lazy_name_get(self.browse(tax_ids).with_user(name_get_uid))
@api.model
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):