Add missing company domain/field
issue4311 review7691002
This commit is contained in:
1 parent
492ffa9f5a
commit
36c1ff8e75
7 files changed
+101
-44
No files matched your search
+13
-4
@@ -326,6 +326,8 @@ class BalanceNonDeferralStart(ModelView):
|
||||
__name__ = 'account.fiscalyear.balance_non_deferral.start'
|
||||
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
|
||||
required=True, domain=[('state', '=', 'open')])
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
||||
'on_change_with_company')
|
||||
journal = fields.Many2One('account.journal', 'Journal', required=True,
|
||||
domain=[
|
||||
('type', '=', 'situation'),
|
||||
@@ -340,16 +342,23 @@ class BalanceNonDeferralStart(ModelView):
|
||||
required=True,
|
||||
domain=[
|
||||
('kind', '!=', 'view'),
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
('company', '=', Eval('company', -1)),
|
||||
('deferral', '=', True),
|
||||
])
|
||||
],
|
||||
depends=['company'])
|
||||
debit_account = fields.Many2One('account.account', 'Debit Account',
|
||||
required=True,
|
||||
domain=[
|
||||
('kind', '!=', 'view'),
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
('company', '=', Eval('company', -1)),
|
||||
('deferral', '=', True),
|
||||
])
|
||||
],
|
||||
depends=['company'])
|
||||
|
||||
@fields.depends('fiscalyear')
|
||||
def on_change_with_company(self, name=None):
|
||||
if self.fiscalyear:
|
||||
return self.fiscalyear.company.id
|
||||
|
||||
|
||||
class BalanceNonDeferral(Wizard):
|
||||
|
||||
@@ -49,8 +49,12 @@ class Move(ModelSQL, ModelView):
|
||||
number = fields.Char('Number', required=True, readonly=True)
|
||||
post_number = fields.Char('Post Number', readonly=True,
|
||||
help='Also known as Folio Number')
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
period = fields.Many2One('account.period', 'Period', required=True,
|
||||
states=_MOVE_STATES, depends=_MOVE_DEPENDS, select=True)
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
states=_MOVE_STATES, depends=_MOVE_DEPENDS + ['company'], select=True)
|
||||
journal = fields.Many2One('account.journal', 'Journal', required=True,
|
||||
states=_MOVE_STATES, depends=_MOVE_DEPENDS)
|
||||
date = fields.Date('Effective Date', required=True, states=_MOVE_STATES,
|
||||
@@ -65,7 +69,10 @@ class Move(ModelSQL, ModelView):
|
||||
('posted', 'Posted'),
|
||||
], 'State', required=True, readonly=True, select=True)
|
||||
lines = fields.One2Many('account.move.line', 'move', 'Lines',
|
||||
states=_MOVE_STATES, depends=_MOVE_DEPENDS,
|
||||
domain=[
|
||||
('account.company', '=', Eval('company', -1)),
|
||||
],
|
||||
states=_MOVE_STATES, depends=_MOVE_DEPENDS + ['company'],
|
||||
context={
|
||||
'journal': Eval('journal'),
|
||||
'period': Eval('period'),
|
||||
@@ -87,8 +94,6 @@ class Move(ModelSQL, ModelView):
|
||||
'"%(move)s" to draft in journal "%(journal)s".'),
|
||||
'modify_posted_move': ('You can not modify move "%s" because '
|
||||
'it is already posted.'),
|
||||
'company_in_move': ('You can not create lines on accounts'
|
||||
'of different companies in move "%s".'),
|
||||
'date_outside_period': ('You can not create move "%(move)s" '
|
||||
'because it\'s date is outside its period.'),
|
||||
'draft_closed_period': ('You can not set to draft move '
|
||||
@@ -111,6 +116,12 @@ class Move(ModelSQL, ModelView):
|
||||
TableHandler = backend.get('TableHandler')
|
||||
cursor = Transaction().cursor
|
||||
table = TableHandler(cursor, cls, module_name)
|
||||
sql_table = cls.__table__()
|
||||
pool = Pool()
|
||||
Period = pool.get('account.period')
|
||||
period = Period.__table__()
|
||||
FiscalYear = pool.get('account.fiscalyear')
|
||||
fiscalyear = FiscalYear.__table__()
|
||||
|
||||
# Migration from 2.4:
|
||||
# - name renamed into number
|
||||
@@ -120,14 +131,29 @@ class Move(ModelSQL, ModelView):
|
||||
if table.column_exist('reference'):
|
||||
table.column_rename('reference', 'post_number')
|
||||
|
||||
created_company = not table.column_exist('company')
|
||||
|
||||
super(Move, cls).__register__(module_name)
|
||||
|
||||
# Migration from 3.4: new company field
|
||||
if created_company:
|
||||
# Don't use UPDATE FROM because SQLite nor MySQL support it.
|
||||
value = period.join(fiscalyear,
|
||||
condition=period.fiscalyear == fiscalyear.id).select(
|
||||
fiscalyear.company,
|
||||
where=period.id == sql_table.period)
|
||||
cursor.execute(*sql_table.update([sql_table.company], [value]))
|
||||
|
||||
table = TableHandler(cursor, cls, module_name)
|
||||
table.index_action(['journal', 'period'], 'add')
|
||||
|
||||
# Add index on create_date
|
||||
table.index_action('create_date', action='add')
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@staticmethod
|
||||
def default_period():
|
||||
Period = Pool().get('account.period')
|
||||
@@ -181,17 +207,8 @@ class Move(ModelSQL, ModelView):
|
||||
def validate(cls, moves):
|
||||
super(Move, cls).validate(moves)
|
||||
for move in moves:
|
||||
move.check_company()
|
||||
move.check_date()
|
||||
|
||||
def check_company(self):
|
||||
company_id = -1
|
||||
for line in self.lines:
|
||||
if company_id < 0:
|
||||
company_id = line.account.company.id
|
||||
if line.account.company.id != company_id:
|
||||
self.raise_user_error('company_in_move', (self.rec_name,))
|
||||
|
||||
def check_date(self):
|
||||
if (self.date < self.period.start_date
|
||||
or self.date > self.period.end_date):
|
||||
@@ -285,17 +302,10 @@ class Move(ModelSQL, ModelView):
|
||||
'''
|
||||
pool = Pool()
|
||||
MoveLine = pool.get('account.move.line')
|
||||
User = pool.get('res.user')
|
||||
line = MoveLine.__table__()
|
||||
|
||||
cursor = Transaction().cursor
|
||||
|
||||
if (Transaction().user == 0
|
||||
and Transaction().context.get('user')):
|
||||
user = Transaction().context.get('user')
|
||||
else:
|
||||
user = Transaction().user
|
||||
company = User(user).company
|
||||
amounts = {}
|
||||
move2draft_lines = {}
|
||||
for sub_move_ids in grouped_slice([m.id for m in moves]):
|
||||
@@ -324,7 +334,7 @@ class Move(ModelSQL, ModelView):
|
||||
amount = Decimal(amount)
|
||||
draft_lines = MoveLine.browse(
|
||||
list(move2draft_lines.get(move.id, [])))
|
||||
if not company.currency.is_zero(amount):
|
||||
if not move.company.currency.is_zero(amount):
|
||||
draft_moves.append(move.id)
|
||||
continue
|
||||
if not draft_lines:
|
||||
@@ -1147,6 +1157,7 @@ class Line(ModelSQL, ModelView):
|
||||
fiscalyears = FiscalYear.search([
|
||||
('start_date', '<=', Transaction().context['date']),
|
||||
('end_date', '>=', Transaction().context['date']),
|
||||
('company', '=', Transaction().context.get('company')),
|
||||
], limit=1)
|
||||
|
||||
fiscalyear_id = fiscalyears and fiscalyears[0].id or 0
|
||||
@@ -1193,6 +1204,7 @@ class Line(ModelSQL, ModelView):
|
||||
if not Transaction().context.get('fiscalyear'):
|
||||
fiscalyears = FiscalYear.search([
|
||||
('state', '=', 'open'),
|
||||
('company', '=', Transaction().context.get('company')),
|
||||
])
|
||||
fiscalyear_ids = [f.id for f in fiscalyears] or [0]
|
||||
else:
|
||||
|
||||
@@ -34,7 +34,14 @@ class Period(ModelSQL, ModelView):
|
||||
('close', 'Close'),
|
||||
], 'State', readonly=True, required=True)
|
||||
post_move_sequence = fields.Many2One('ir.sequence', 'Post Move Sequence',
|
||||
domain=[('code', '=', 'account.move')],
|
||||
domain=[
|
||||
('code', '=', 'account.move'),
|
||||
['OR',
|
||||
('company', '=', None),
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
],
|
||||
depends=['company'],
|
||||
context={'code': 'account.move'})
|
||||
type = fields.Selection([
|
||||
('standard', 'Standard'),
|
||||
@@ -42,7 +49,7 @@ class Period(ModelSQL, ModelView):
|
||||
], 'Type', required=True,
|
||||
states=_STATES, depends=_DEPENDS, select=True)
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company',),
|
||||
'get_company', searcher='search_company')
|
||||
'on_change_with_company', searcher='search_company')
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
@@ -78,9 +85,6 @@ class Period(ModelSQL, ModelView):
|
||||
'overlap.'),
|
||||
'check_move_sequence': ('Period "%(first)s" and "%(second)s" '
|
||||
'have the same sequence.'),
|
||||
'check_move_sequence_company': ('Company of sequence '
|
||||
'"%(sequence)s" does not match the company of period '
|
||||
'"%(period)s" to which it is assigned to.'),
|
||||
'fiscalyear_dates': ('Dates of period "%s" are outside '
|
||||
'are outside it\'s fiscal year dates.'),
|
||||
})
|
||||
@@ -93,8 +97,10 @@ class Period(ModelSQL, ModelView):
|
||||
def default_type():
|
||||
return 'standard'
|
||||
|
||||
def get_company(self, name):
|
||||
return self.fiscalyear.company.id
|
||||
@fields.depends('fiscalyear')
|
||||
def on_change_with_company(self, name=None):
|
||||
if self.fiscalyear:
|
||||
return self.fiscalyear.company.id
|
||||
|
||||
@classmethod
|
||||
def search_company(cls, name, clause):
|
||||
@@ -148,12 +154,6 @@ class Period(ModelSQL, ModelView):
|
||||
'first': self.rec_name,
|
||||
'second': periods[0].rec_name,
|
||||
})
|
||||
if (self.post_move_sequence.company and
|
||||
self.post_move_sequence.company != self.fiscalyear.company):
|
||||
self.raise_user_error('check_move_sequence_company', {
|
||||
'sequence': self.post_move_sequence.rec_name,
|
||||
'period': self.rec_name,
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def find(cls, company_id, date=None, exception=True, test_state=True):
|
||||
|
||||
@@ -627,9 +627,13 @@ class Tax(ModelSQL, ModelView):
|
||||
depends=['company', 'type'])
|
||||
invoice_base_code = fields.Many2One('account.tax.code',
|
||||
'Invoice Base Code',
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
states={
|
||||
'readonly': Eval('type') == 'none',
|
||||
}, depends=['type'])
|
||||
},
|
||||
depends=['type', 'company'])
|
||||
invoice_base_sign = fields.Numeric('Invoice Base Sign', digits=(2, 0),
|
||||
help='Usualy 1 or -1',
|
||||
states={
|
||||
@@ -638,9 +642,13 @@ class Tax(ModelSQL, ModelView):
|
||||
}, depends=['type'])
|
||||
invoice_tax_code = fields.Many2One('account.tax.code',
|
||||
'Invoice Tax Code',
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
states={
|
||||
'readonly': Eval('type') == 'none',
|
||||
}, depends=['type'])
|
||||
},
|
||||
depends=['type', 'company'])
|
||||
invoice_tax_sign = fields.Numeric('Invoice Tax Sign', digits=(2, 0),
|
||||
help='Usualy 1 or -1',
|
||||
states={
|
||||
@@ -654,15 +662,23 @@ class Tax(ModelSQL, ModelView):
|
||||
}, depends=['type'])
|
||||
credit_note_base_sign = fields.Numeric('Credit Note Base Sign',
|
||||
digits=(2, 0), help='Usualy 1 or -1',
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
states={
|
||||
'required': Eval('type') != 'none',
|
||||
'readonly': Eval('type') == 'none',
|
||||
}, depends=['type'])
|
||||
},
|
||||
depends=['type', 'company'])
|
||||
credit_note_tax_code = fields.Many2One('account.tax.code',
|
||||
'Credit Note Tax Code',
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
states={
|
||||
'readonly': Eval('type') == 'none',
|
||||
}, depends=['type'])
|
||||
},
|
||||
depends=['type', 'company'])
|
||||
credit_note_tax_sign = fields.Numeric('Credit Note Tax Sign',
|
||||
digits=(2, 0), help='Usualy 1 or -1',
|
||||
states={
|
||||
@@ -919,11 +935,21 @@ class TaxLine(ModelSQL, ModelView):
|
||||
amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
|
||||
required=True, depends=['currency_digits'])
|
||||
code = fields.Many2One('account.tax.code', 'Code', select=True,
|
||||
required=True)
|
||||
required=True,
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
depends=['company'])
|
||||
tax = fields.Many2One('account.tax', 'Tax', select=True,
|
||||
ondelete='RESTRICT')
|
||||
ondelete='RESTRICT',
|
||||
domain=[
|
||||
('company', '=', Eval('company', -1)),
|
||||
],
|
||||
depends=['company'])
|
||||
move_line = fields.Many2One('account.move.line', 'Move Line',
|
||||
required=True, select=True, ondelete='CASCADE')
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
||||
'on_change_with_company')
|
||||
|
||||
@fields.depends('move_line')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
@@ -935,6 +961,11 @@ class TaxLine(ModelSQL, ModelView):
|
||||
def on_change_tax(self):
|
||||
self.code = None
|
||||
|
||||
@fields.depends('_parent_move_line.account')
|
||||
def on_change_with_company(self, name=None):
|
||||
if self.move_line:
|
||||
return self.move_line.account.company.id
|
||||
|
||||
|
||||
class TaxRuleTemplate(ModelSQL, ModelView):
|
||||
'Tax Rule Template'
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form string="Account Move" cursor="journal">
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
<newline/>
|
||||
<label name="number"/>
|
||||
<field name="number"/>
|
||||
<label name="post_number"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree string="Account Moves">
|
||||
<field name="company"/>
|
||||
<field name="number"/>
|
||||
<field name="post_number"/>
|
||||
<field name="journal"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree string="Periods">
|
||||
<field name="company"/>
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="type"/>
|
||||
|
||||
Reference in new issue
Block a user