mirror of
https://github.com/NaN-tic/trytond-patches.git
synced 2023-12-14 06:03:03 +01:00
389 lines
15 KiB
Diff
389 lines
15 KiB
Diff
# exporting patch:
|
|
# HG changeset patch
|
|
# User Cédric Krier <ced@b2ck.com>
|
|
# Date 1417619588 -3600
|
|
# Wed Dec 03 16:13:08 2014 +0100
|
|
# Node ID 42b9acc4c201b883197c3ebc8385f6e1072cd076
|
|
# Parent d57626d6cf3e20cd28861a1d5c37cc7c064bd21c
|
|
# Add missing company domain/field
|
|
|
|
# issue4311
|
|
# review7691002
|
|
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 fiscalyear.py
|
|
--- .a/trytond/trytond/modules/account/fiscalyear.py Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/fiscalyear.py Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -326,6 +326,8 @@
|
|
__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 @@
|
|
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):
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 move.py
|
|
--- .a/trytond/trytond/modules/account/move.py Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/move.py Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -49,8 +49,12 @@
|
|
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 @@
|
|
('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 @@
|
|
'"%(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 @@
|
|
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,8 +131,19 @@
|
|
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')
|
|
|
|
@@ -129,6 +151,10 @@
|
|
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')
|
|
return Period.find(Transaction().context.get('company'),
|
|
@@ -181,17 +207,8 @@
|
|
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 @@
|
|
'''
|
|
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]):
|
|
@@ -326,7 +326,7 @@
|
|
if not isinstance(amount, Decimal):
|
|
amount = Decimal(amount)
|
|
draft_lines = MoveLine.browse(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 @@
|
|
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 @@
|
|
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:
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 period.py
|
|
--- .a/trytond/trytond/modules/account/period.py Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/period.py Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -34,7 +34,14 @@
|
|
('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 @@
|
|
], '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 @@
|
|
'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 @@
|
|
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 @@
|
|
'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):
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 tax.py
|
|
--- .a/trytond/trytond/modules/account/tax.py Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/tax.py Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -627,9 +627,13 @@
|
|
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 @@
|
|
}, 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 @@
|
|
}, 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 @@
|
|
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 @@
|
|
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'
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 view/move_form.xml
|
|
--- .a/trytond/trytond/modules/account/view/move_form.xml Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/view/move_form.xml Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -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"/>
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 view/move_tree.xml
|
|
--- .a/trytond/trytond/modules/account/view/move_tree.xml Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/view/move_tree.xml Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -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"/>
|
|
diff -r d57626d6cf3e -r 42b9acc4c201 view/period_tree.xml
|
|
--- .a/trytond/trytond/modules/account/view/period_tree.xml Tue Dec 02 12:54:29 2014 +0100
|
|
+++ .b/trytond/trytond/modules/account/view/period_tree.xml Wed Dec 03 16:13:08 2014 +0100
|
|
@@ -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"/>
|