From c5b1fbc47856fc8aed3856cad9bcb75243e1fa31 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Wed, 28 Mar 2007 14:41:48 +0000 Subject: [PATCH] ACCOUNT: add multi-company into base accounting bzr revid: mga@tinyerp.com-9d1120f18bae244eeb46ca3a8f00919a8498058b --- addons/account/__terp__.py | 2 +- addons/account/account.py | 76 ++++++++++++- addons/account/account_analytic_line.py | 10 +- addons/account/account_invoice_view.xml | 8 +- addons/account/account_move_line.py | 12 ++ addons/account/account_view.xml | 10 +- addons/account/account_wizard.xml | 6 + addons/account/invoice.py | 65 ++++++----- addons/account/project/project.py | 24 +++- addons/account/project/project_view.xml | 2 + addons/account/wizard/__init__.py | 1 + .../wizard/wizard_account_duplicate.py} | 41 ++++--- addons/multi_company/account.py | 107 ------------------ addons/multi_company/multi_company_demo.xml | 24 +++- addons/multi_company_account/__init__.py | 1 - addons/multi_company_account/__terp__.py | 12 -- .../multi_company_account_demo.xml | 5 - .../multi_company_account_view.xml | 17 --- 18 files changed, 218 insertions(+), 205 deletions(-) rename addons/{multi_company_account/multi_company_account.py => account/wizard/wizard_account_duplicate.py} (57%) delete mode 100644 addons/multi_company/account.py delete mode 100644 addons/multi_company_account/__init__.py delete mode 100644 addons/multi_company_account/__terp__.py delete mode 100644 addons/multi_company_account/multi_company_account_demo.xml delete mode 100644 addons/multi_company_account/multi_company_account_view.xml diff --git a/addons/account/__terp__.py b/addons/account/__terp__.py index 0939ed6c61e..0cf8c586d40 100644 --- a/addons/account/__terp__.py +++ b/addons/account/__terp__.py @@ -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 diff --git a/addons/account/account.py b/addons/account/account.py index b4ffc003f65..c956bb2e280 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -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' diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 8e0938e6f00..a067a1e3090 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -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: diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 51c2784cff3..d7b4e389292 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -43,8 +43,8 @@ - - + + @@ -137,7 +137,7 @@ - + @@ -164,6 +164,8 @@ + + diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 4e04688f175..979a0af24fc 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -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 {} diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 5e179648028..d1b05290dbb 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -105,6 +105,8 @@ + + @@ -141,7 +143,7 @@ - + @@ -529,7 +531,8 @@ form
- + + @@ -582,7 +585,8 @@ - + + diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml index d1adf2916a5..7a3a5a96ec8 100644 --- a/addons/account/account_wizard.xml +++ b/addons/account/account_wizard.xml @@ -186,6 +186,12 @@ id="wizard_invoice_state_cancel"/> + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 831a6fe0ea3..530a04324a1 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -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 diff --git a/addons/account/project/project.py b/addons/account/project/project.py index 614ac7e172e..9f1eeb9956e 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.py @@ -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' diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml index 03a9665fb92..39c159fbf8f 100644 --- a/addons/account/project/project_view.xml +++ b/addons/account/project/project_view.xml @@ -32,6 +32,7 @@ + @@ -49,6 +50,7 @@ + diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index 5e6f8249463..1ab3dee5a74 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -54,3 +54,4 @@ import wizard_fiscalyear_close import wizard_vat import wizard_invoice_state +import wizard_account_duplicate diff --git a/addons/multi_company_account/multi_company_account.py b/addons/account/wizard/wizard_account_duplicate.py similarity index 57% rename from addons/multi_company_account/multi_company_account.py rename to addons/account/wizard/wizard_account_duplicate.py index 393ca1bc474..d188466ec0c 100644 --- a/addons/multi_company_account/multi_company_account.py +++ b/addons/account/wizard/wizard_account_duplicate.py @@ -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 = ''' + + +''' +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') diff --git a/addons/multi_company/account.py b/addons/multi_company/account.py deleted file mode 100644 index ae04f90358e..00000000000 --- a/addons/multi_company/account.py +++ /dev/null @@ -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() diff --git a/addons/multi_company/multi_company_demo.xml b/addons/multi_company/multi_company_demo.xml index 4aba5e81431..9fe9c67f124 100644 --- a/addons/multi_company/multi_company_demo.xml +++ b/addons/multi_company/multi_company_demo.xml @@ -1,18 +1,34 @@ - + - Tiny2 sprl + Tiny Editor - Tiny2 sprl + Tiny Editor + Free Business Solutions - Web: http://tiny2.be - Tel: (+32).81.81.37.00 - Bank: CPH 126-2013269-07 + Web: http://tiny.be - Tel: (+32).81.81.37.00 - Bank: CPH 126-2013269-07 IBAN: BE74 1262 0132 6907 - SWIFT: GKCCBEBB - VAT: BE0477.472.701 + + Tiny Integrator + + + + Tiny Integrator + + + Free Business Solutions + Web: http://tiny.be - Tel: (+32).81.81.37.00 - Bank: CPH 126-2013269-07 + IBAN: BE74 1262 0132 6907 - SWIFT: GKCCBEBB - VAT: BE0477.472.701 + + + + diff --git a/addons/multi_company_account/__init__.py b/addons/multi_company_account/__init__.py deleted file mode 100644 index 4e257e25d92..00000000000 --- a/addons/multi_company_account/__init__.py +++ /dev/null @@ -1 +0,0 @@ -import multi_company_account diff --git a/addons/multi_company_account/__terp__.py b/addons/multi_company_account/__terp__.py deleted file mode 100644 index 5958e0a1be7..00000000000 --- a/addons/multi_company_account/__terp__.py +++ /dev/null @@ -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 -} diff --git a/addons/multi_company_account/multi_company_account_demo.xml b/addons/multi_company_account/multi_company_account_demo.xml deleted file mode 100644 index b9db83b8c07..00000000000 --- a/addons/multi_company_account/multi_company_account_demo.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/addons/multi_company_account/multi_company_account_view.xml b/addons/multi_company_account/multi_company_account_view.xml deleted file mode 100644 index 8eae3137155..00000000000 --- a/addons/multi_company_account/multi_company_account_view.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - account.analytic.account.multicompany - account.analytic.account - - - - - - - - - -