ACCOUNT: add multi-company into base accounting
bzr revid: mga@tinyerp.com-9d1120f18bae244eeb46ca3a8f00919a8498058b
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name" : "Accounting and financial management",
|
||||
"version" : "1.0",
|
||||
"depends" : ["product"],
|
||||
"depends" : ["product", "base"],
|
||||
"author" : "Tiny",
|
||||
"description": """Financial and accounting module that covers:
|
||||
General accounting
|
||||
|
||||
@@ -155,16 +155,31 @@ class account_account(osv.osv):
|
||||
res = {}
|
||||
for account_id, sum in cr.fetchall():
|
||||
res[account_id] = round(sum,2)
|
||||
cr.execute("SELECT a.id, a.company_id FROM account_account a where id in (%s)" % acc_set)
|
||||
resc = dict(cr.fetchall())
|
||||
cr.execute("SELECT id, currency_id FROM res_company")
|
||||
rescur = dict(cr.fetchall())
|
||||
for id in ids:
|
||||
ids3 = self.search(cr, uid, [('parent_id', 'child_of', [id])])
|
||||
to_currency_id = rescur[resc[id]]
|
||||
for idx in ids3:
|
||||
if idx <> id:
|
||||
res.setdefault(id, 0.0)
|
||||
res[id] += res.get(idx, 0.0)
|
||||
if resc[idx]<>resc[id] and resc[idx] and resc[id]:
|
||||
from_currency_id = rescur[resc[idx]]
|
||||
res[id] += self.pool.get('res.currency').compute(cr, uid, from_currency_id, to_currency_id, res.get(idx, 0.0), context=context)
|
||||
else:
|
||||
res[id] += res.get(idx, 0.0)
|
||||
for id in ids:
|
||||
res[id] = round(res.get(id,0.0), 2)
|
||||
return res
|
||||
|
||||
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
result[rec.id] = (rec.company_id.currency_id.id,rec.company_id.currency_id.code)
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128, required=True, translate=True, select=True),
|
||||
'sign': fields.selection([(-1, 'Negative'), (1, 'Positive')], 'Sign', required=True, help='Allows to change the displayed amount of the balance to see positive results instead of negative ones in expenses accounts'),
|
||||
@@ -182,14 +197,23 @@ class account_account(osv.osv):
|
||||
'tax_ids': fields.many2many('account.tax', 'account_account_tax_default_rel', 'account_id','tax_id', 'Default Taxes'),
|
||||
|
||||
'active': fields.boolean('Active'),
|
||||
'note': fields.text('Note')
|
||||
'note': fields.text('Note'),
|
||||
'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Currency'),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
|
||||
def _default_company(self, cr, uid, context={}):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
if user.company_id:
|
||||
return user.company_id.id
|
||||
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
|
||||
_defaults = {
|
||||
'sign': lambda *a: 1,
|
||||
'type': lambda *a: 'view',
|
||||
'active': lambda *a: True,
|
||||
'reconcile': lambda *a: False,
|
||||
'close_method': lambda *a: 'balance',
|
||||
'company_id': _default_company,
|
||||
}
|
||||
def _check_recursion(self, cr, uid, ids):
|
||||
level = 100
|
||||
@@ -233,6 +257,18 @@ class account_account(osv.osv):
|
||||
name = record['code']+' - '+name
|
||||
res.append((record['id'],name ))
|
||||
return res
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context={}):
|
||||
account = self.browse(cr, uid, id, context=context)
|
||||
new_child_ids = []
|
||||
default['parent_id'] = False
|
||||
if account:
|
||||
for child in account.child_id:
|
||||
new_child_ids.append(self.copy(cr, uid, child.id, default, context=context))
|
||||
default['child_id'] = [(6, 0, new_child_ids)]
|
||||
else:
|
||||
default['child_id'] = False
|
||||
return super(account_account, self).copy(cr, uid, id, default, context=context)
|
||||
account_account()
|
||||
|
||||
|
||||
@@ -351,10 +387,18 @@ class account_fiscalyear(osv.osv):
|
||||
'date_start': fields.date('Start date', required=True),
|
||||
'date_stop': fields.date('End date', required=True),
|
||||
'period_ids': fields.one2many('account.period', 'fiscalyear_id', 'Periods'),
|
||||
'state': fields.selection([('draft','Draft'), ('done','Done')], 'State', redonly=True)
|
||||
'state': fields.selection([('draft','Draft'), ('done','Done')], 'State', redonly=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
|
||||
def _default_company(self, cr, uid, context={}):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
if user.company_id:
|
||||
return user.company_id.id
|
||||
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
|
||||
_defaults = {
|
||||
'state': lambda *a: 'draft',
|
||||
'company_id': _default_company,
|
||||
}
|
||||
_order = "code"
|
||||
def create_period3(self,cr, uid, ids, context={}):
|
||||
@@ -595,11 +639,18 @@ class account_move(osv.osv):
|
||||
amount = 0
|
||||
line_ids = []
|
||||
line_draft_ids = []
|
||||
company_id=None
|
||||
for line in move.line_id:
|
||||
amount += line.debit - line.credit
|
||||
line_ids.append(line.id)
|
||||
if line.state=='draft':
|
||||
line_draft_ids.append(line.id)
|
||||
|
||||
if not company_id:
|
||||
company_id = line.account_id.company_id.id
|
||||
if not company_id == line.account_id.company_id.id:
|
||||
raise osv.except_osv('Error', 'Couldn\'t create move between different companies')
|
||||
|
||||
if abs(amount) < 0.0001:
|
||||
if not len(line_draft_ids):
|
||||
continue
|
||||
@@ -735,7 +786,16 @@ class account_tax_code(osv.osv):
|
||||
'sum_period': fields.function(_sum_period, method=True, string="Period Sum"),
|
||||
'parent_id': fields.many2one('account.tax.code', 'Parent Code', select=True),
|
||||
'child_ids': fields.one2many('account.tax.code', 'parent_id', 'Childs Codes'),
|
||||
'line_ids': fields.one2many('account.move.line', 'tax_code_id', 'Lines')
|
||||
'line_ids': fields.one2many('account.move.line', 'tax_code_id', 'Lines'),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
def _default_company(self, cr, uid, context={}):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
if user.company_id:
|
||||
return user.company_id.id
|
||||
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
|
||||
_defaults = {
|
||||
'company_id': _default_company,
|
||||
}
|
||||
_order = 'name'
|
||||
account_tax_code()
|
||||
@@ -786,7 +846,14 @@ class account_tax(osv.osv):
|
||||
'ref_base_sign': fields.float('Base Code Sign', help="Usualy 1 or -1."),
|
||||
'ref_tax_sign': fields.float('Tax Code Sign', help="Usualy 1 or -1."),
|
||||
'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes"),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
|
||||
def _default_company(self, cr, uid, context={}):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
if user.company_id:
|
||||
return user.company_id.id
|
||||
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
|
||||
_defaults = {
|
||||
'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''',
|
||||
'applicable_type': lambda *a: 'true',
|
||||
@@ -800,6 +867,7 @@ class account_tax(osv.osv):
|
||||
'tax_sign': lambda *a: 1,
|
||||
'base_sign': lambda *a: 1,
|
||||
'include_base_amount': lambda *a: False,
|
||||
'company_id': _default_company,
|
||||
}
|
||||
_order = 'sequence'
|
||||
|
||||
|
||||
@@ -51,11 +51,19 @@ class account_analytic_line(osv.osv):
|
||||
'user_id' : fields.many2one('res.users', 'User',),
|
||||
'ref': fields.char('Ref.', size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
_order = 'date'
|
||||
def _check_company(self, cr, uid, ids):
|
||||
lines = self.browse(cr, uid, ids)
|
||||
for l in lines:
|
||||
if l.move_id and not l.account_id.company_id.id == l.move_id.account_id.company_id.id:
|
||||
return False
|
||||
return True
|
||||
_constraints = [
|
||||
(_check_company, 'You can not create analytic line that is not in the same company than the account line', ['account_id'])
|
||||
]
|
||||
|
||||
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, unit=False, context={}):
|
||||
if unit_amount and prod_id:
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
<notebook>
|
||||
<page string="Line">
|
||||
<field name="name" select="1" colspan="3"/>
|
||||
<field name="account_id" on_change="onchange_account_id(parent.partner_id,account_id)" />
|
||||
<field name="account_analytic_id" domain="[('type','<>','view')]" />
|
||||
<field name="account_id" on_change="onchange_account_id(parent.partner_id,account_id)" domain="[('company_id', '=', parent.company_id)]"/>
|
||||
<field name="account_analytic_id" domain="[('type','<>','view'), ('company_id', '=', parent.company_id)]" />
|
||||
<newline/>
|
||||
<field name="product_id" select="1" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id)"/>
|
||||
<field name="uos_id"/>
|
||||
@@ -137,7 +137,7 @@
|
||||
<field name="address_invoice_id" domain="[('partner_id','=',partner_id)]"/>
|
||||
<field name="partner_bank_id" domain="[('partner_id','=',partner_id)]"/>
|
||||
|
||||
<field name="account_id" domain="[('type','<>','view')]" />
|
||||
<field name="account_id" domain="[('type','<>','view'), ('company_id', '=', company_id)]" />
|
||||
|
||||
<field name="payment_term" on_change="onchange_payment_term(payment_term)" />
|
||||
<field name="date_due" select="1"/>
|
||||
@@ -164,6 +164,8 @@
|
||||
<field name="tax_line" nolabel="1" widget="one2many_list" colspan="4"/>
|
||||
</page>
|
||||
<page string="Other Information">
|
||||
<field name="company_id"/>
|
||||
<newline/>
|
||||
<field name="reference" select="1"/>
|
||||
<field name="origin"/>
|
||||
<field name="address_contact_id" domain="[('partner_id','=',partner_id)]" colspan="3"/>
|
||||
|
||||
@@ -200,6 +200,18 @@ class account_move_line(osv.osv):
|
||||
('credit_debit1', 'CHECK (credit*debit=0)', 'Wrong credit or debit value in accounting entry !'),
|
||||
('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in accounting entry !'),
|
||||
]
|
||||
|
||||
def _check_no_view(self, cr, uid, ids):
|
||||
lines = self.browse(cr, uid, ids)
|
||||
for l in lines:
|
||||
if l.account_id.type == 'view':
|
||||
return False
|
||||
return True
|
||||
|
||||
_constraints = [
|
||||
(_check_no_view, 'You can not create move line on view account.', ['account_id'])
|
||||
]
|
||||
|
||||
def onchange_partner_id(self, cr, uid, ids, move_id, partner_id, account_id=None, debit=0, credit=0, journal=False):
|
||||
if (not partner_id) or account_id:
|
||||
return {}
|
||||
|
||||
@@ -105,6 +105,8 @@
|
||||
<notebook>
|
||||
<page string="General Information">
|
||||
<field name="name" select="1" colspan="3"/>
|
||||
<field name="company_id" select="1"/>
|
||||
<newline/>
|
||||
<field name="type" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="shortcut"/>
|
||||
@@ -141,7 +143,7 @@
|
||||
<tree string="Account Chart">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="currency_id" string="CUR"/>
|
||||
<field name="company_currency_id"/>
|
||||
<field name="debit"/>
|
||||
<field name="credit"/>
|
||||
<field name="balance"/>
|
||||
@@ -529,7 +531,8 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Account Tax Code">
|
||||
<field name="name" select="1" colspan="3"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="company_id"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="parent_id" select="1"/>
|
||||
<newline/>
|
||||
@@ -582,7 +585,8 @@
|
||||
<form string="Account Tax">
|
||||
<notebook>
|
||||
<page string="Tax Definition">
|
||||
<field name="name" select="1" colspan="3"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="company_id"/>
|
||||
<field name="tax_group" select="1"/>
|
||||
<field name="active" select="1" />
|
||||
<field name="type" select="1"/>
|
||||
|
||||
@@ -186,6 +186,12 @@
|
||||
id="wizard_invoice_state_cancel"/>
|
||||
|
||||
|
||||
<wizard
|
||||
string="Duplicate"
|
||||
model="account.account"
|
||||
name="account.wizard.account.duplicate"
|
||||
id="wizard_account_duplicate"
|
||||
keyword="tree_but_action"/>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
||||
+34
-31
@@ -128,8 +128,8 @@ class account_invoice(osv.osv):
|
||||
'amount_tax': fields.function(_amount_tax, method=True, string='Tax', store=True),
|
||||
'amount_total': fields.function(_amount_total, method=True, string='Total', store=True),
|
||||
'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal', required=True, relate=True,readonly=True,
|
||||
states={'draft':[('readonly',False)]}),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal', required=True, relate=True,readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'type': lambda *a: 'out_invoice',
|
||||
@@ -137,6 +137,7 @@ class account_invoice(osv.osv):
|
||||
'state': lambda *a: 'draft',
|
||||
'journal_id': _get_journal,
|
||||
'currency_id': _get_currency,
|
||||
'company_id': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id,
|
||||
}
|
||||
|
||||
def unlink(self, cr, uid, ids):
|
||||
@@ -256,19 +257,21 @@ class account_invoice(osv.osv):
|
||||
return True
|
||||
|
||||
def action_move_create(self, cr, uid, ids, *args):
|
||||
company_currency = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
|
||||
id_set = ','.join([str(i) for i in ids])
|
||||
cr.execute('SELECT * FROM account_invoice WHERE move_id IS NULL AND id IN ('+id_set+')')
|
||||
for inv in cr.dictfetchall():
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
for inv in self.browse(cr, uid, ids):
|
||||
if inv.move_id:
|
||||
continue
|
||||
|
||||
company_currency = inv.account_id.company_id.currency_id.id
|
||||
# create the analytical lines
|
||||
line_ids = self.read(cr, uid, [inv['id']], ['invoice_line'])[0]['invoice_line']
|
||||
line_ids = self.read(cr, uid, [inv.id], ['invoice_line'])[0]['invoice_line']
|
||||
ils = self.pool.get('account.invoice.line').read(cr, uid, line_ids)
|
||||
if inv['type'] in ('out_invoice', 'in_refund'):
|
||||
if inv.type in ('out_invoice', 'in_refund'):
|
||||
sign = 1
|
||||
else:
|
||||
sign = -1
|
||||
# one move line per invoice line
|
||||
iml = self.pool.get('account.invoice.line').move_line_get(cr, uid, inv['id'])
|
||||
iml = self.pool.get('account.invoice.line').move_line_get(cr, uid, inv.id)
|
||||
for il in iml:
|
||||
if il['account_analytic_id']:
|
||||
il['analytic_lines'] = [(0,0, {
|
||||
@@ -276,46 +279,46 @@ class account_invoice(osv.osv):
|
||||
'date': inv['date_invoice'],
|
||||
'account_id': il['account_analytic_id'],
|
||||
'unit_amount': il['quantity'],
|
||||
'amount': il['price'] * sign,
|
||||
'amount': cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context={'date': inv.date_invoice}) * sign,
|
||||
'product_id': il['product_id'],
|
||||
'product_uom_id': il['uos_id'],
|
||||
'general_account_id': il['account_id'],
|
||||
'journal_id': self._get_journal_analytic(cr, uid, inv['type'])
|
||||
'journal_id': self._get_journal_analytic(cr, uid, inv.type)
|
||||
})]
|
||||
|
||||
# one move line per tax line
|
||||
iml += self.pool.get('account.invoice.tax').move_line_get(cr, uid, inv['id'])
|
||||
iml += self.pool.get('account.invoice.tax').move_line_get(cr, uid, inv.id)
|
||||
|
||||
|
||||
# create one move line for the total and possibly adjust the other lines amount
|
||||
total = 0
|
||||
total_currency = 0
|
||||
for i in iml:
|
||||
if inv['currency_id'] != company_currency:
|
||||
i['currency_id'] = inv['currency_id']
|
||||
if inv.currency_id.id != company_currency:
|
||||
i['currency_id'] = inv.currency_id.id
|
||||
i['amount_currency'] = i['price']
|
||||
i['price'] = self.pool.get('res.currency').compute(cr, uid, inv['currency_id'], company_currency, i['price'], context={'date': inv['date_invoice']})
|
||||
i['price'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, i['price'], context={'date': inv.date_invoice})
|
||||
else:
|
||||
i['amount_currency'] = False
|
||||
i['currency_id'] = False
|
||||
i['ref'] = inv['number']
|
||||
if inv['type'] in ('out_invoice','in_refund'):
|
||||
i['ref'] = inv.number
|
||||
if inv.type in ('out_invoice','in_refund'):
|
||||
total += i['price']
|
||||
total_currency += i['amount_currency'] or i['price']
|
||||
i['price'] = - i['price']
|
||||
else:
|
||||
total -= i['price']
|
||||
total_currency -= i['amount_currency'] or i['price']
|
||||
acc_id = inv['account_id']
|
||||
acc_id = inv.account_id.id
|
||||
|
||||
name = inv['name']
|
||||
if inv['payment_term']:
|
||||
totlines = self.pool.get('account.payment.term').compute(cr, uid, inv['payment_term'], total)
|
||||
if inv.payment_term:
|
||||
totlines = self.pool.get('account.payment.term').compute(cr, uid, inv.payment_term.id, total)
|
||||
res_amount_currency = total_currency
|
||||
i = 0
|
||||
for t in totlines:
|
||||
if inv['currency_id'] != company_currency:
|
||||
amount_currency = self.pool.get('res.currency').compute(cr, uid, company_currency, inv['currency_id'], t[1])
|
||||
if inv.currency_id.id != company_currency:
|
||||
amount_currency = cur_obj.compute(cr, uid, company_currency, inv.currency_id.id, t[1])
|
||||
else:
|
||||
amount_currency = False
|
||||
|
||||
@@ -325,12 +328,12 @@ class account_invoice(osv.osv):
|
||||
if i == len(totlines):
|
||||
amount_currency += res_amount_currency
|
||||
|
||||
iml.append({ 'type':'dest', 'name':name, 'price': t[1], 'account_id':acc_id, 'date_maturity': t[0], 'amount_currency': amount_currency, 'currency_id': inv['currency_id'], 'ref': inv['number']})
|
||||
iml.append({ 'type':'dest', 'name':name, 'price': t[1], 'account_id':acc_id, 'date_maturity': t[0], 'amount_currency': amount_currency, 'currency_id': inv.currency_id.id, 'ref': inv.number})
|
||||
else:
|
||||
iml.append({ 'type':'dest', 'name':name, 'price': total, 'account_id':acc_id, 'date_maturity' : inv['date_due'] or False, 'amount_currency': total_currency, 'currency_id': inv['currency_id'], 'ref': inv['number']})
|
||||
iml.append({ 'type':'dest', 'name':name, 'price': total, 'account_id':acc_id, 'date_maturity' : inv.date_due or False, 'amount_currency': total_currency, 'currency_id': inv.currency_id.id, 'ref': inv.number})
|
||||
|
||||
date = inv['date_invoice']
|
||||
part = inv['partner_id']
|
||||
date = inv.date_invoice
|
||||
part = inv.partner_id.id
|
||||
line = map(lambda x:(0,0,{
|
||||
'date':date,
|
||||
'date_maturity': x.get('date_maturity', False),
|
||||
@@ -346,20 +349,20 @@ class account_invoice(osv.osv):
|
||||
'tax_amount': x.get('tax_amount', False),
|
||||
'ref':x.get('ref',False) }) ,iml)
|
||||
|
||||
journal_id = inv['journal_id'] #self._get_journal(cr, uid, {'type': inv['type']})
|
||||
journal_id = inv.journal_id.id #self._get_journal(cr, uid, {'type': inv['type']})
|
||||
journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
|
||||
if journal.sequence_id:
|
||||
name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
|
||||
|
||||
move = {'name': name, 'line_id': line, 'journal_id': journal_id}
|
||||
if inv['period_id']:
|
||||
move['period_id'] = inv['period_id']
|
||||
if inv.period_id:
|
||||
move['period_id'] = inv.period_id.id
|
||||
for i in line:
|
||||
i[2]['period_id'] = inv['period_id']
|
||||
i[2]['period_id'] = inv.period_id.id
|
||||
move_id = self.pool.get('account.move').create(cr, uid, move)
|
||||
|
||||
# make the invoice point to that move
|
||||
self.write(cr, uid, [inv['id']], {'move_id': move_id})
|
||||
self.write(cr, uid, [inv.id], {'move_id': move_id})
|
||||
|
||||
self._log_event(cr, uid, ids)
|
||||
return True
|
||||
|
||||
@@ -51,6 +51,7 @@ class account_analytic_account(osv.osv):
|
||||
return res
|
||||
|
||||
def _debit_calc(self, cr, uid, ids, name, arg, context={}):
|
||||
# XXX to be improved like in account.account
|
||||
res = {}
|
||||
for account in self.browse(cr, uid, ids):
|
||||
node_balance = reduce(operator.add, [line.amount for line in account.line_ids if line.amount>0], 0)
|
||||
@@ -64,7 +65,11 @@ class account_analytic_account(osv.osv):
|
||||
res = {}
|
||||
for account in self.browse(cr, uid, ids):
|
||||
node_balance = reduce(operator.add, [line.amount for line in account.line_ids], 0)
|
||||
child_balance = reduce(operator.add, [child.balance for child in account.child_ids], 0)
|
||||
child_balance = reduce(operator.add,
|
||||
[self.pool.get('res.currency').compute(cr, uid,
|
||||
child.company_id.currency_id.id,
|
||||
account.company_id.currency_id.id, child.balance, context=context)
|
||||
for child in account.child_ids], 0)
|
||||
res[account.id] = node_balance + child_balance
|
||||
for id in ids:
|
||||
res[id] = round(res.get(id, 0.0),2)
|
||||
@@ -96,6 +101,11 @@ class account_analytic_account(osv.osv):
|
||||
res = self.name_get(cr, uid, ids)
|
||||
return dict(res)
|
||||
|
||||
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
result[rec.id] = (rec.company_id.currency_id.id,rec.company_id.currency_id.code) or False
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Account name', size=64, required=True),
|
||||
@@ -108,8 +118,8 @@ class account_analytic_account(osv.osv):
|
||||
'child_ids': fields.one2many('account.analytic.account', 'parent_id', 'Childs Accounts'),
|
||||
'line_ids': fields.one2many('account.analytic.line', 'account_id', 'Analytic entries'),
|
||||
'balance' : fields.function(_balance_calc, method=True, type='float', string='Balance'),
|
||||
'debit' : fields.function(_debit_calc, method=True, type='float', string='Balance'),
|
||||
'credit' : fields.function(_credit_calc, method=True, type='float', string='Balance'),
|
||||
'debit' : fields.function(_debit_calc, method=True, type='float', string='Debit'),
|
||||
'credit' : fields.function(_credit_calc, method=True, type='float', string='Credit'),
|
||||
'quantity': fields.function(_quantity_calc, method=True, type='float', string='Quantity'),
|
||||
'quantity_max': fields.float('Maximal quantity'),
|
||||
'partner_id' : fields.many2one('res.partner', 'Associated partner'),
|
||||
@@ -118,11 +128,19 @@ class account_analytic_account(osv.osv):
|
||||
'date_start': fields.date('Date Start'),
|
||||
'date': fields.date('Date End'),
|
||||
'stats_ids': fields.one2many('report.hr.timesheet.invoice.journal', 'account_id', string='Statistics', readonly=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Currency'),
|
||||
}
|
||||
|
||||
def _default_company(self, cr, uid, context={}):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
if user.company_id:
|
||||
return user.company_id.id
|
||||
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
|
||||
_defaults = {
|
||||
'active' : lambda *a : True,
|
||||
'type' : lambda *a : 'normal',
|
||||
'company_id': _default_company,
|
||||
}
|
||||
|
||||
_order = 'parent_id desc,code'
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<field name="code"/>
|
||||
<field name="partner_id" />
|
||||
<field name="date" />
|
||||
<field name="company_currency_id"/>
|
||||
<field name="balance" />
|
||||
<field name="quantity" />
|
||||
</tree>
|
||||
@@ -49,6 +50,7 @@
|
||||
<field name="name" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="parent_id" on_change="on_change_parent(parent_id)" />
|
||||
<field name="company_id" select="1"/>
|
||||
<field name="type" select="1" />
|
||||
<field name="partner_id" select="1" />
|
||||
<newline/>
|
||||
|
||||
@@ -54,3 +54,4 @@ import wizard_fiscalyear_close
|
||||
import wizard_vat
|
||||
|
||||
import wizard_invoice_state
|
||||
import wizard_account_duplicate
|
||||
|
||||
+28
-13
@@ -1,8 +1,6 @@
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
||||
#
|
||||
# $Id: product_extended.py 5702 2007-02-20 15:33:28Z ced $
|
||||
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
@@ -27,15 +25,32 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv
|
||||
import wizard
|
||||
import pooler
|
||||
|
||||
class account_analytic_account(osv.osv):
|
||||
_inherit = 'account.analytic.account'
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id
|
||||
}
|
||||
account_analytic_account()
|
||||
duplicate_form = '''<?xml version="1.0"?>
|
||||
<form string="Duplicate account charts">
|
||||
<field name="company_id"/>
|
||||
</form>'''
|
||||
|
||||
duplicate_fields = {
|
||||
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
|
||||
}
|
||||
|
||||
def _do_duplicate(self, cr, uid, data, context):
|
||||
account_obj = pooler.get_pool(cr.dbname).get('account.account')
|
||||
account_obj.copy(cr, uid, data['id'], data['form'], context=context)
|
||||
return {}
|
||||
|
||||
class wizard_account_duplicate(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch': duplicate_form, 'fields': duplicate_fields, 'state': (('end', 'Cancel'), ('duplicate', 'Duplicate'))},
|
||||
},
|
||||
'duplicate': {
|
||||
'actions': [_do_duplicate],
|
||||
'result': {'type': 'state', 'state': 'end'},
|
||||
},
|
||||
}
|
||||
wizard_account_duplicate('account.wizard.account.duplicate')
|
||||
@@ -1,107 +0,0 @@
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
||||
#
|
||||
# $Id: product_extended.py 5702 2007-02-20 15:33:28Z ced $
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# garantees and support are strongly adviced to contract a Free Software
|
||||
# Service Company
|
||||
#
|
||||
# This program is Free Software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv
|
||||
|
||||
class account_analytic_account(osv.osv):
|
||||
_inherit = 'account.analytic.account'
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
}
|
||||
_defaults = {
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id
|
||||
}
|
||||
account_analytic_account()
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Accounts
|
||||
#----------------------------------------------------------
|
||||
class account_account(osv.osv):
|
||||
_inherit = "account.account"
|
||||
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result = {}
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
result[rec.id] = rec.company_id and (rec.company_id.currency_id.id,rec.company_id.currency_id.code) or False
|
||||
return result
|
||||
def _balance(self, cr, uid, ids, field_name, arg, context={}):
|
||||
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
|
||||
acc_set = ",".join(map(str, ids2))
|
||||
res = {}
|
||||
cr.execute("SELECT a.id, COALESCE(SUM((l.debit-l.credit)),0) FROM account_account a LEFT JOIN account_move_line l ON (a.id=l.account_id) WHERE a.id IN (%s) and l.active AND l.state<>'draft' GROUP BY a.id" % acc_set)
|
||||
for account_id, sum in cr.fetchall():
|
||||
res[account_id] = round(sum,2)
|
||||
|
||||
cr.execute("SELECT a.id, a.company_id FROM account_account a where id in (%s)" % acc_set)
|
||||
resc = dict(cr.fetchall())
|
||||
|
||||
compc = {}
|
||||
for id in ids:
|
||||
ids3 = self.search(cr, uid, [('parent_id', 'child_of', [id])])
|
||||
to_currency_id = self._company_currency(cr,uid,resc[id],compc,context)
|
||||
for idx in ids3:
|
||||
if idx <> id:
|
||||
res.setdefault(id, 0.0)
|
||||
if resc[idx]<>resc[id] and resc[idx] and resc[id]:
|
||||
from_currency_id = self._company_currency(cr,uid,resc[idx],compc,context)
|
||||
res[id] += self.pool.get('res.currency').compute(cr, uid, from_currency_id, to_currency_id, res.get(idx, 0.0), context=context)
|
||||
else:
|
||||
res[id] += res.get(idx, 0.0)
|
||||
for id in ids:
|
||||
res[id] = round(res.get(id,0.0), 2)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Currency'),
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
'balance': fields.function(_balance, digits=(16,2), method=True, string='Balance'),
|
||||
}
|
||||
_defaults = {
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id
|
||||
}
|
||||
account_account()
|
||||
|
||||
class account_fiscalyear(osv.osv):
|
||||
_inherit = "account.fiscalyear"
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
}
|
||||
_defaults = {
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id
|
||||
}
|
||||
account_fiscalyear()
|
||||
|
||||
class account_tax(osv.osv):
|
||||
_inherit = 'account.tax'
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
}
|
||||
_defaults = {
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id
|
||||
}
|
||||
account_tax()
|
||||
@@ -1,18 +1,34 @@
|
||||
<?xml version="1.0"?>
|
||||
<terp>
|
||||
<data update="1">
|
||||
<data noupdate="1">
|
||||
<record model="res.partner" id="second_partner">
|
||||
<field name="name">Tiny2 sprl</field>
|
||||
<field name="name">Tiny Editor</field>
|
||||
</record>
|
||||
|
||||
<record model="res.company" id="second_company">
|
||||
<field name="name">Tiny2 sprl</field>
|
||||
<field name="name">Tiny Editor</field>
|
||||
<field name="partner_id" ref="base.main_partner"/>
|
||||
<field name="parent_id" ref="base.main_company"/>
|
||||
<field name="rml_header1">Free Business Solutions</field>
|
||||
<field name="rml_footer1">Web: http://tiny2.be - Tel: (+32).81.81.37.00 - Bank: CPH 126-2013269-07</field>
|
||||
<field name="rml_footer1">Web: http://tiny.be - Tel: (+32).81.81.37.00 - Bank: CPH 126-2013269-07</field>
|
||||
<field name="rml_footer2">IBAN: BE74 1262 0132 6907 - SWIFT: GKCCBEBB - VAT: BE0477.472.701</field>
|
||||
<field name="currency_id" ref="base.EUR"/>
|
||||
</record>
|
||||
|
||||
<record model="res.partner" id="ter_partner">
|
||||
<field name="name">Tiny Integrator</field>
|
||||
</record>
|
||||
|
||||
<record model="res.company" id="ter_company">
|
||||
<field name="name">Tiny Integrator</field>
|
||||
<field name="partner_id" ref="base.main_partner"/>
|
||||
<field name="parent_id" ref="base.main_company"/>
|
||||
<field name="rml_header1">Free Business Solutions</field>
|
||||
<field name="rml_footer1">Web: http://tiny.be - Tel: (+32).81.81.37.00 - Bank: CPH 126-2013269-07</field>
|
||||
<field name="rml_footer2">IBAN: BE74 1262 0132 6907 - SWIFT: GKCCBEBB - VAT: BE0477.472.701</field>
|
||||
<field name="currency_id" ref="base.EUR"/>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import multi_company_account
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"name" : "Multi company for account module",
|
||||
"version" : "0.1",
|
||||
"author" : "Tiny",
|
||||
"depends" : ["account",],
|
||||
"category" : "Generic Modules/Base",
|
||||
"init_xml" : [],
|
||||
"demo_xml" : ["multi_company_account_demo.xml",],
|
||||
"update_xml" : ["multi_company_account_view.xml"],
|
||||
"active": False,
|
||||
"installable": True
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<terp>
|
||||
<data noupdate="1">
|
||||
</data>
|
||||
</terp>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<terp>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="view_analytic_account_multicompany">
|
||||
<field name="name">account.analytic.account.multicompany</field>
|
||||
<field name="model">account.analytic.account</field>
|
||||
<field name="inherit_id" ref="account.view_account_analytic_account_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="user_id" position="after">
|
||||
<field name="company_id" select="1"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
Reference in New Issue
Block a user