Port move template to the new API
This commit is contained in:
parent
f3d7658bbe
commit
bc32c437da
@ -20,99 +20,96 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, orm
|
from openerp.osv import fields, orm, api
|
||||||
|
from openerp.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class AccountMoveTemplate(orm.Model):
|
class AccountMoveTemplate(orm.Model):
|
||||||
|
|
||||||
_inherit = 'account.document.template'
|
|
||||||
_name = 'account.move.template'
|
_name = 'account.move.template'
|
||||||
|
_inherit = 'account.document.template'
|
||||||
|
|
||||||
_columns = {
|
@api.model
|
||||||
'company_id': fields.many2one(
|
def _company_get(self):
|
||||||
'res.company',
|
return self.env['res.company']._company_default_get(
|
||||||
'Company',
|
object='account.move.template'
|
||||||
required=True,
|
|
||||||
change_default=True
|
|
||||||
),
|
|
||||||
'template_line_ids': fields.one2many(
|
|
||||||
'account.move.template.line',
|
|
||||||
'template_id',
|
|
||||||
'Template Lines'
|
|
||||||
),
|
|
||||||
'cross_journals': fields.boolean('Cross-Journals'),
|
|
||||||
'transitory_acc_id': fields.many2one(
|
|
||||||
'account.account',
|
|
||||||
'Transitory account',
|
|
||||||
required=False
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
def _get_default(self, cr, uid, context=None):
|
|
||||||
self.pool.get('res.company')._company_default_get(
|
|
||||||
cr, uid, 'account.move.template', context=context
|
|
||||||
)
|
)
|
||||||
_defaults = {
|
|
||||||
'company_id': _get_default
|
|
||||||
}
|
|
||||||
|
|
||||||
def _check_different_journal(self, cr, uid, ids, context=None):
|
company_id = fields.Many2one(
|
||||||
|
comodel_name='res.company',
|
||||||
|
string='Company',
|
||||||
|
required=True,
|
||||||
|
change_default=True,
|
||||||
|
default=_company_get,
|
||||||
|
)
|
||||||
|
template_line_ids = fields.One2many(
|
||||||
|
comodel_name='account.move.template.line',
|
||||||
|
inverse_name='template_id',
|
||||||
|
string='Template Lines'
|
||||||
|
)
|
||||||
|
cross_journals = fields.Boolean(string='Cross-Journals')
|
||||||
|
transitory_acc_id = fields.Many2one(
|
||||||
|
comodel_name='account.account',
|
||||||
|
string='Transitory account',
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.constrains('journal_id')
|
||||||
|
def _check_different_journal(self):
|
||||||
# Check that the journal on these lines are different/same in the case
|
# Check that the journal on these lines are different/same in the case
|
||||||
# of cross journals/single journal
|
# of cross journals/single journal
|
||||||
journal_ids = []
|
journal_ids = []
|
||||||
all_journal_ids = []
|
all_journal_ids = []
|
||||||
move_template = self.pool.get('account.move.template').browse(
|
error_message = (
|
||||||
cr, uid, ids)[0]
|
u'If the template is "cross-journals", the Journals must be '
|
||||||
if not move_template.template_line_ids:
|
u'different, if the template does not "cross-journals" the '
|
||||||
return True
|
u'Journals must be the same!',
|
||||||
|
)
|
||||||
|
for move_template in self:
|
||||||
|
if move_template.template_line_ids:
|
||||||
for template_line in move_template.template_line_ids:
|
for template_line in move_template.template_line_ids:
|
||||||
all_journal_ids.append(template_line.journal_id.id)
|
all_journal_ids.append(template_line.journal_id.id)
|
||||||
if template_line.journal_id.id not in journal_ids:
|
if template_line.journal_id.id not in journal_ids:
|
||||||
journal_ids.append(template_line.journal_id.id)
|
journal_ids.append(template_line.journal_id.id)
|
||||||
if move_template.cross_journals:
|
if move_template.cross_journals:
|
||||||
return len(all_journal_ids) == len(journal_ids)
|
if len(all_journal_ids) != len(journal_ids):
|
||||||
else:
|
raise ValidationError(error_message)
|
||||||
return len(journal_ids) == 1
|
elif len(journal_ids) != 1:
|
||||||
|
raise ValidationError(error_message)
|
||||||
_constraints = [
|
|
||||||
(_check_different_journal,
|
|
||||||
'If the template is "cross-journals", the Journals must be different,'
|
|
||||||
'if the template does not "cross-journals" '
|
|
||||||
'the Journals must be the same!',
|
|
||||||
['journal_id'])
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class AccountMoveTemplateLine(orm.Model):
|
class AccountMoveTemplateLine(orm.Model):
|
||||||
_name = 'account.move.template.line'
|
_name = 'account.move.template.line'
|
||||||
_inherit = 'account.document.template.line'
|
_inherit = 'account.document.template.line'
|
||||||
|
|
||||||
_columns = {
|
journal_id = fields.Many2one(
|
||||||
'journal_id': fields.many2one(
|
comodel_name='account.journal',
|
||||||
'account.journal',
|
string='Journal',
|
||||||
'Journal',
|
|
||||||
required=True
|
required=True
|
||||||
),
|
)
|
||||||
'account_id': fields.many2one(
|
account_id = fields.Many2one(
|
||||||
'account.account',
|
comodel_name='account.account',
|
||||||
'Account',
|
string='Account',
|
||||||
required=True,
|
required=True,
|
||||||
ondelete="cascade"
|
ondelete="cascade"
|
||||||
),
|
),
|
||||||
'move_line_type': fields.selection(
|
move_line_type = fields.Selection(
|
||||||
[('cr', 'Credit'),
|
[('cr', 'Credit'), ('dr', 'Debit')],
|
||||||
('dr', 'Debit')],
|
string='Move Line Type',
|
||||||
'Move Line Type',
|
|
||||||
required=True
|
required=True
|
||||||
),
|
)
|
||||||
'analytic_account_id': fields.many2one(
|
analytic_account_id = fields.Many2one(
|
||||||
'account.analytic.account',
|
comodel_name='account.analytic.account',
|
||||||
'Analytic Account',
|
string='Analytic Account',
|
||||||
ondelete="cascade"
|
ondelete="cascade"
|
||||||
),
|
)
|
||||||
'template_id': fields.many2one('account.move.template', 'Template'),
|
template_id = fields.Many2one(
|
||||||
'account_tax_id': fields.many2one('account.tax', 'Tax'),
|
comodel_name='account.move.template',
|
||||||
}
|
string='Template'
|
||||||
|
)
|
||||||
|
account_tax_id = fields.Many2one(
|
||||||
|
comodel_name='account.tax',
|
||||||
|
string='Tax'
|
||||||
|
)
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
('sequence_template_uniq', 'unique (template_id,sequence)',
|
('sequence_template_uniq', 'unique (template_id,sequence)',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user