From 86041cba194ee019204e8993a23af97a849ed873 Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Mon, 8 Sep 2008 17:09:41 +0530 Subject: [PATCH 01/20] Minor bugfixes and set the digits of code for accounts on charts of templates bzr revid: jvo@tinyerp.com-20080908113941-0m19546uzwfe8jau --- addons/account/account.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index a771bed6144..1ce6c4dbd7e 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1867,6 +1867,9 @@ class wizard_multi_charts_accounts(osv.osv_memory): obj_journal = self.pool.get('account.journal') obj_acc_template = self.pool.get('account.account.template') + if obj_multi.code_digits<=5: + raise osv.except_osv(_('User Error'), _('Account code should be of more than 5 digits.')) + # Creating Account obj_acc_root = obj_multi.chart_template_id.account_root_id tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id @@ -1889,7 +1892,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'name': (tax_code_root_id == tax_code_template.id) and obj_multi.company_id.name or tax_code_template.name, 'code': tax_code_template.code, 'info': tax_code_template.info, - 'parent_id': tax_code_template.parent_id and tax_code_template_ref[tax_code_template.parent_id.id] or False, + 'parent_id': tax_code_template.parent_id and ((tax_code_template.parent_id.id in tax_code_template_ref) and tax_code_template_ref[tax_code_template.parent_id.id]) or False, 'company_id': company_id, 'sign': tax_code_template.sign, } @@ -1907,7 +1910,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'type':tax.type, 'applicable_type': tax.applicable_type, 'domain':tax.domain, - 'parent_id': tax.parent_id and tax_template_ref[tax.parent_id.id] or False, + 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False, 'child_depend': tax.child_depend, 'python_compute': tax.python_compute, 'python_compute_inv': tax.python_compute_inv, @@ -1933,7 +1936,6 @@ class wizard_multi_charts_accounts(osv.osv_memory): } tax_template_ref[tax.id] = new_tax - #deactivate the parent_store functionnality on account_account for rapidity purpose self.pool._init = True children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id])]) @@ -1942,17 +1944,23 @@ class wizard_multi_charts_accounts(osv.osv_memory): for tax in account_template.tax_ids: tax_ids.append(tax_template_ref[tax.id]) #create the account_account + dig=obj_multi.code_digits + code_main=len(account_template.code) + code_acc=account_template.code + if account_template.type <>'view': + if code_main<=dig: + code_acc=str(code_acc) + (str('0'*(dig-code_main))) vals={ 'name': (obj_acc_root.id == account_template.id) and obj_multi.company_id.name or account_template.name, #'sign': account_template.sign, 'currency_id': account_template.currency_id and account_template.currency_id.id or False, - 'code': account_template.code, + 'code': code_acc[:dig], 'type': account_template.type, 'user_type': account_template.user_type or False, 'reconcile': account_template.reconcile, 'shortcut': account_template.shortcut, 'note': account_template.note, - 'parent_id': account_template.parent_id and acc_template_ref[account_template.parent_id.id] or False, + 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False, 'tax_ids': [(6,0,tax_ids)], 'company_id': company_id, } @@ -2015,7 +2023,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): #'sign': ref_acc_bank.sign, 'currency_id': line.currency_id and line.currency_id.id or False, 'code': ref_acc_bank.code+str(current_num), - 'type': 'cash', + 'type': 'other', 'user_type': account_template.user_type or False, 'reconcile': True, 'parent_id': acc_template_ref[ref_acc_bank.id] or False, From 547f2e8ecb3d329d93887341bdf1992bee1ad1db Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Mon, 8 Sep 2008 18:13:37 +0530 Subject: [PATCH 02/20] removed old journal creation scheme bzr revid: jvo@tinyerp.com-20080908124337-8lowflgakxdq8kgg --- addons/account/account.py | 118 ++++++++++++++++---------------- addons/account/account_view.xml | 4 +- 2 files changed, 60 insertions(+), 62 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 1ce6c4dbd7e..f9b2e33a44c 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1562,66 +1562,64 @@ class account_config_fiscalyear(osv.osv_memory): account_config_fiscalyear() - - -class account_config_journal_bank_accounts(osv.osv_memory): - _name='account.config.journal.bank.account' - _columns = { - 'name':fields.char('Journal Name', size=64), - 'lines_id': fields.one2many('account.config.journal.bank.account.line', 'journal_id', 'Journal Lines'), - } - - def action_cancel(self,cr,uid,ids,conect=None): - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'ir.module.module.configuration.wizard', - 'type': 'ir.actions.act_window', - 'target':'new', - } - - def action_create(self, cr, uid, ids, context=None): - config_res=self.read(cr,uid,ids)[0] - res_obj = self.pool.get('account.journal') - line_obj=self.pool.get('account.config.journal.bank.account.line') - if 'lines_id' in config_res and config_res['lines_id']: - lines=line_obj.read(cr,uid,config_res['lines_id']) - for res in lines: - sequence_ids=self.pool.get('ir.sequence').search(cr,uid,[('name','=','Account Journal')]) - if 'name' in res and 'bank_account_id' in res and 'view_id' in res and sequence_ids and len(sequence_ids): - vals={ - 'name':res['name'], - 'type':'cash', - 'view_id':res['view_id'], - 'default_credit_account_id':res['bank_account_id'], - 'default_debit_account_id':res['bank_account_id'], - 'sequence_id':sequence_ids[0] - } - res_obj.create(cr, uid, vals, context=context) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'ir.module.module.configuration.wizard', - 'type': 'ir.actions.act_window', - 'target':'new', - } - -account_config_journal_bank_accounts() - -class account_config_journal_bank_accounts_line(osv.osv_memory): - _name='account.config.journal.bank.account.line' - def _journal_view_get(self, cr, uid, context={}): - journal_obj = self.pool.get('account.journal.view') - ids = journal_obj.search(cr, uid, []) - res = journal_obj.read(cr, uid, ids, ['id', 'name'], context) - return [(r['id'], r['name']) for r in res] - _columns = { - 'name':fields.char('Journal Name', size=64,required=True), - 'bank_account_id':fields.many2one('account.account', 'Bank Account', required=True, domain=[('type','=','cash')]), - 'view_id':fields.selection(_journal_view_get, 'Journal View', required=True), - 'journal_id':fields.many2one('account.config.journal.bank.account', 'Journal', required=True), - } -account_config_journal_bank_accounts_line() +#class account_config_journal_bank_accounts(osv.osv_memory): +# _name='account.config.journal.bank.account' +# _columns = { +# 'name':fields.char('Journal Name', size=64), +# 'lines_id': fields.one2many('account.config.journal.bank.account.line', 'journal_id', 'Journal Lines'), +# } +# +# def action_cancel(self,cr,uid,ids,conect=None): +# return { +# 'view_type': 'form', +# "view_mode": 'form', +# 'res_model': 'ir.module.module.configuration.wizard', +# 'type': 'ir.actions.act_window', +# 'target':'new', +# } +# +# def action_create(self, cr, uid, ids, context=None): +# config_res=self.read(cr,uid,ids)[0] +# res_obj = self.pool.get('account.journal') +# line_obj=self.pool.get('account.config.journal.bank.account.line') +# if 'lines_id' in config_res and config_res['lines_id']: +# lines=line_obj.read(cr,uid,config_res['lines_id']) +# for res in lines: +# sequence_ids=self.pool.get('ir.sequence').search(cr,uid,[('name','=','Account Journal')]) +# if 'name' in res and 'bank_account_id' in res and 'view_id' in res and sequence_ids and len(sequence_ids): +# vals={ +# 'name':res['name'], +# 'type':'cash', +# 'view_id':res['view_id'], +# 'default_credit_account_id':res['bank_account_id'], +# 'default_debit_account_id':res['bank_account_id'], +# 'sequence_id':sequence_ids[0] +# } +# res_obj.create(cr, uid, vals, context=context) +# return { +# 'view_type': 'form', +# "view_mode": 'form', +# 'res_model': 'ir.module.module.configuration.wizard', +# 'type': 'ir.actions.act_window', +# 'target':'new', +# } +# +#account_config_journal_bank_accounts() +# +#class account_config_journal_bank_accounts_line(osv.osv_memory): +# _name='account.config.journal.bank.account.line' +# def _journal_view_get(self, cr, uid, context={}): +# journal_obj = self.pool.get('account.journal.view') +# ids = journal_obj.search(cr, uid, []) +# res = journal_obj.read(cr, uid, ids, ['id', 'name'], context) +# return [(r['id'], r['name']) for r in res] +# _columns = { +# 'name':fields.char('Journal Name', size=64,required=True), +# 'bank_account_id':fields.many2one('account.account', 'Bank Account', required=True, domain=[('type','=','cash')]), +# 'view_id':fields.selection(_journal_view_get, 'Journal View', required=True), +# 'journal_id':fields.many2one('account.config.journal.bank.account', 'Journal', required=True), +# } +#account_config_journal_bank_accounts_line() # ---------------------------------------------- # Account Templates : Account, Tax and charts. diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 2fb7c30d4a5..20aaa5ba7ea 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1463,12 +1463,12 @@ open - + From 05c1b80ef45670123899111a3e3ed1781233a3bd Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Mon, 8 Sep 2008 19:19:58 +0530 Subject: [PATCH 03/20] partial commit for account move task bzr revid: jvo@tinyerp.com-20080908134958-suq7pil6qgf18qje --- addons/account/account_move_line.py | 4 ++++ addons/account/account_view.xml | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index ec17ec2a031..b6c5da18e76 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -70,12 +70,15 @@ class account_move_line(osv.osv): # Compute simple values data = super(account_move_line, self).default_get(cr, uid, fields, context) +# print "fields",fields + if not 'move_id' in fields: #we are not in manual entry return data period_obj = self.pool.get('account.period') tax_obj=self.pool.get('account.tax') +# print "par" # Compute the current move move_id = False partner_id = False @@ -342,6 +345,7 @@ class account_move_line(osv.osv): def onchange_partner_id(self, cr, uid, ids, move_id, partner_id, account_id=None, debit=0, credit=0, date=False, journal=False): val = {} val['date_maturity'] = False +# print "partner_id",partner_id,account_id,debit,credit,date if not partner_id: return {'value':val} if not date: diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 20aaa5ba7ea..bb05d051b7c 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -801,7 +801,7 @@ - +
@@ -828,6 +828,7 @@ + @@ -855,7 +856,18 @@ form
- + + + + + Entries Encoding by Move + account.move + form + tree,form + + + + Entry lines @@ -1417,7 +1429,7 @@ - + From e40894da2baf75f46b2168b5480b330badd8bad9 Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Tue, 9 Sep 2008 12:58:14 +0530 Subject: [PATCH 04/20] Provided complete onchange effect to account.move.line bzr revid: jvo@tinyerp.com-20080909072814-otddki2jqrn4ek60 --- addons/account/account_move_line.py | 6 ++---- addons/account/account_view.xml | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index b6c5da18e76..5003fe10942 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -70,15 +70,12 @@ class account_move_line(osv.osv): # Compute simple values data = super(account_move_line, self).default_get(cr, uid, fields, context) -# print "fields",fields - if not 'move_id' in fields: #we are not in manual entry return data period_obj = self.pool.get('account.period') tax_obj=self.pool.get('account.tax') -# print "par" # Compute the current move move_id = False partner_id = False @@ -345,12 +342,13 @@ class account_move_line(osv.osv): def onchange_partner_id(self, cr, uid, ids, move_id, partner_id, account_id=None, debit=0, credit=0, date=False, journal=False): val = {} val['date_maturity'] = False -# print "partner_id",partner_id,account_id,debit,credit,date + if not partner_id: return {'value':val} if not date: date = now().strftime('%Y-%m-%d') part = self.pool.get('res.partner').browse(cr, uid, partner_id) + if part.property_payment_term and part.property_payment_term.line_ids:# Compute Maturity Date in val ! line = part.property_payment_term.line_ids[0] next_date = mx.DateTime.strptime(date, '%Y-%m-%d') + RelativeDateTime(days=line.days) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index bb05d051b7c..1785fefcf92 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -807,7 +807,7 @@ - + @@ -830,7 +830,7 @@ - + From c7fe56aacfa60f2adb3c57765a8fdf826aa72d3c Mon Sep 17 00:00:00 2001 From: jvo <> Date: Wed, 10 Sep 2008 14:47:19 +0530 Subject: [PATCH 05/20] Removed journal configuraion wizard entry from ir.model.access.csv bzr revid: jvo-20080910091719-xl8ftvk1oe2hh1v3 --- addons/account/security/ir.model.access.csv | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/account/security/ir.model.access.csv b/addons/account/security/ir.model.access.csv index 68fa798ad38..3f65271a2ae 100644 --- a/addons/account/security/ir.model.access.csv +++ b/addons/account/security/ir.model.access.csv @@ -20,8 +20,6 @@ access_account_model_line,account.model.line,model_account_model_line,account.gr access_account_subscription,account.subscription,model_account_subscription,account.group_account_user,1,1,1,1 access_account_subscription_line,account.subscription.line,model_account_subscription_line,account.group_account_user,1,1,1,1 access_account_config_fiscalyear,account.config.fiscalyear,model_account_config_fiscalyear,account.group_account_manager,1,1,1,1 -access_account_config_journal_bank_account,account.config.journal.bank.account,model_account_config_journal_bank_account,account.group_account_manager,1,1,1,1 -access_account_config_journal_bank_account_line,account.config.journal.bank.account.line,model_account_config_journal_bank_account_line,account.group_account_manager,1,1,1,1 access_account_tax_template,account.tax.template,model_account_tax_template,account.group_account_manager,1,1,1,1 access_account_account_template,account.account.template,model_account_account_template,account.group_account_manager,1,1,1,1 access_account_tax_code_template,account.tax.code.template,model_account_tax_code_template,account.group_account_manager,1,1,1,1 From 294e474bc0b289812042e6301362cdc343c377e2 Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Wed, 10 Sep 2008 17:02:29 +0530 Subject: [PATCH 06/20] Corrected manual entry behaviour on account.move form for unsaved move.line bzr revid: jvo@tinyerp.com-20080910113229-0gqd0uff2vbed2kv --- addons/account/account_move_line.py | 28 +++++++++++++++++++++++++++- addons/account/account_view.xml | 3 +-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 5003fe10942..12f3682cf56 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -70,6 +70,33 @@ class account_move_line(osv.osv): # Compute simple values data = super(account_move_line, self).default_get(cr, uid, fields, context) + # Starts: Manual entry from account.move form + if context.get('lines',[]): + + total_new=0.00 + for i in context['lines']: + total_new +=(i[2]['debit'] or 0.00)- (i[2]['credit'] or 0.00) + for item in i[2]: + data[item]=i[2][item] + if context['journal']: + journal_obj=self.pool.get('account.journal').browse(cr,uid,context['journal']) + if journal_obj.type == 'purchase': + if total_new>0: + account = journal_obj.default_credit_account_id + else: + account = journal_obj.default_debit_account_id + else: + if total_new>0: + account = journal_obj.default_credit_account_id + else: + account = journal_obj.default_debit_account_id + data['account_id'] = account.id + s = -total_new + data['debit'] = s>0 and s or 0.0 + data['credit'] = s<0 and -s or 0.0 + return data + # Ends: Manual entry from account.move form + if not 'move_id' in fields: #we are not in manual entry return data @@ -649,7 +676,6 @@ class account_move_line(osv.osv): def create(self, cr, uid, vals, context=None, check=True): if not context: context={} - account_obj = self.pool.get('account.account') tax_obj=self.pool.get('account.tax') diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 1785fefcf92..6099ec57535 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -801,7 +801,7 @@ - +
@@ -828,7 +828,6 @@ - From 5ae5ba465fd5c300b3edc10371147cebc5e4f03a Mon Sep 17 00:00:00 2001 From: qdp Date: Thu, 11 Sep 2008 11:28:30 +0200 Subject: [PATCH 07/20] *bugfixed: the customer tax and supplier tax were inversed in the product_id_change method of invoice line. bzr revid: qdp@tinyerp.com-20080911092830-tqkdvmel8e25hn8p --- addons/account/invoice.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 93f91811b0f..86ea0fbd2b2 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -804,11 +804,10 @@ class account_invoice_line(osv.osv): context.update({'lang': lang}) res = self.pool.get('product.product').browse(cr, uid, product, context=context) taxep=None - if partner_id: - lang=self.pool.get('res.partner').read(cr, uid, [partner_id])[0]['lang'] + lang=self.pool.get('res.partner').read(cr, uid, [partner_id])[0]['lang'] tax_obj = self.pool.get('account.tax') if type in ('out_invoice', 'out_refund'): - taxep = self.pool.get('res.partner').browse(cr, uid, partner_id).property_account_supplier_tax + taxep = self.pool.get('res.partner').browse(cr, uid, partner_id).property_account_tax if not taxep or not taxep.id: tax_id = map(lambda x: x.id, res.taxes_id) else: @@ -817,7 +816,7 @@ class account_invoice_line(osv.osv): if not t.tax_group==taxep.tax_group: tax_id.append(t.id) else: - taxep = self.pool.get('res.partner').browse(cr, uid, partner_id).property_account_tax + taxep = self.pool.get('res.partner').browse(cr, uid, partner_id).property_account_supplier_tax if not taxep or not taxep.id: tax_id = map(lambda x: x.id, res.supplier_taxes_id) else: From cf7a92483b9dd17935f739eeeacc655a1bbc2801 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 11 Sep 2008 15:32:28 +0530 Subject: [PATCH 08/20] modify account_budget_crossover - becaz all referece of budget on account is moved to account_budget_crossover bzr revid: mra@tinyerp.com-20080911100228-kgdwn1f1xerxl126 --- addons/account_budget_crossover/__terp__.py | 4 +- .../account_budget_wizard.xml | 9 + .../crossovered_budget.py | 198 +++++++++++--- .../crossovered_budget_report.xml | 10 + .../crossovered_budget_view.xml | 250 ++++++++++++------ .../report/__init__.py | 1 + .../report/budget_report.py | 78 ++++++ .../report/budget_report.rml | 248 +++++++++++++++++ .../security/ir.model.access.csv | 8 +- .../wizard/__init__.py | 3 + .../wizard/wizard_budget_report.py | 61 +++++ .../wizard/wizard_budget_spread.py | 66 +++++ 12 files changed, 811 insertions(+), 125 deletions(-) create mode 100644 addons/account_budget_crossover/account_budget_wizard.xml create mode 100644 addons/account_budget_crossover/report/budget_report.py create mode 100644 addons/account_budget_crossover/report/budget_report.rml create mode 100644 addons/account_budget_crossover/wizard/wizard_budget_report.py create mode 100644 addons/account_budget_crossover/wizard/wizard_budget_spread.py diff --git a/addons/account_budget_crossover/__terp__.py b/addons/account_budget_crossover/__terp__.py index 94139ce16c5..9231b606400 100644 --- a/addons/account_budget_crossover/__terp__.py +++ b/addons/account_budget_crossover/__terp__.py @@ -7,7 +7,7 @@ "category" : "Generic Modules/Accounting", "description": """This module allow accountants to manage analytic and crossovered budgets. - Once the Master Budgets and the Budgets defined (in Financial Management/Configuration/Budgets/), the Project Managers can set the planned amount on each Analytic Account. + Once the Master Budgets and the Budgets defined (in Financial Management/Configuration/Budgets/), the Project Managers can set the planned amount on each Analytic Account. The accountant has the possibility to see the total of amount planned for each Budget and Master Budget in order to ensure the total planned is not greater/lower than what he planned for this Budget/Master Budget. Each list of record can also be switched to a graphical view of it. @@ -23,7 +23,7 @@ "init_xml" : [], "demo_xml" : [], "update_xml" : [ - "security/ir.model.access.csv", + "security/ir.model.access.csv","account_budget_wizard.xml", "crossovered_budget_view.xml","crossovered_budget_report.xml","crossovered_budget_workflow.xml" ], "active": False, diff --git a/addons/account_budget_crossover/account_budget_wizard.xml b/addons/account_budget_crossover/account_budget_wizard.xml new file mode 100644 index 00000000000..c45957da787 --- /dev/null +++ b/addons/account_budget_crossover/account_budget_wizard.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/addons/account_budget_crossover/crossovered_budget.py b/addons/account_budget_crossover/crossovered_budget.py index 461bab436a5..420926bbaf4 100644 --- a/addons/account_budget_crossover/crossovered_budget.py +++ b/addons/account_budget_crossover/crossovered_budget.py @@ -10,6 +10,76 @@ import datetime def strToDate(dt): dt_date=datetime.date(int(dt[0:4]),int(dt[5:7]),int(dt[8:10])) return dt_date +#moved from account/account.py +# --------------------------------------------------------- +# Budgets +# --------------------------------------------------------- +class account_budget_post(osv.osv): + _name = 'account.budget.post' + _description = 'Budget item' + _columns = { + 'code': fields.char('Code', size=64, required=True), + 'name': fields.char('Name', size=256, required=True), + 'dotation_ids': fields.one2many('account.budget.post.dotation', 'post_id', 'Expenses'), + 'account_ids': fields.many2many('account.account', 'account_budget_rel', 'budget_id', 'account_id', 'Accounts'), + 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'general_budget_id', 'Budget Lines'), + } + _defaults = { + } + + def spread(self, cr, uid, ids, fiscalyear_id=False, amount=0.0): + dobj = self.pool.get('account.budget.post.dotation') + for o in self.browse(cr, uid, ids): + # delete dotations for this post + dobj.unlink(cr, uid, dobj.search(cr, uid, [('post_id','=',o.id)])) + + # create one dotation per period in the fiscal year, and spread the total amount/quantity over those dotations + fy = self.pool.get('account.fiscalyear').browse(cr, uid, [fiscalyear_id])[0] + num = len(fy.period_ids) + for p in fy.period_ids: + dobj.create(cr, uid, {'post_id': o.id, 'period_id': p.id, 'amount': amount/num}) + return True +account_budget_post() + +class account_budget_post_dotation(osv.osv): + def _tot_planned(self, cr, uid, ids,name,args,context): + res={} + for line in self.browse(cr, uid, ids): + if line.period_id: + obj_period=self.pool.get('account.period').browse(cr, uid,line.period_id.id) + + total_days=strToDate(obj_period.date_stop) - strToDate(obj_period.date_start) + budget_id=line.post_id and line.post_id.id or False + query="select id from crossovered_budget_lines where general_budget_id= '"+ str(budget_id) + "' AND (date_from >='" +obj_period.date_start +"' and date_from <= '"+obj_period.date_stop + "') OR (date_to >='" +obj_period.date_start +"' and date_to <= '"+obj_period.date_stop + "') OR (date_from <'" +obj_period.date_start +"' and date_to > '"+obj_period.date_stop + "')" + cr.execute(query) + res1=cr.fetchall() + + tot_planned=0.00 + for record in res1: + obj_lines = self.pool.get('crossovered.budget.lines').browse(cr, uid,record[0]) + count_days = min(strToDate(obj_period.date_stop),strToDate(obj_lines.date_to)) - max(strToDate(obj_period.date_start), strToDate(obj_lines.date_from)) + days_in_period = count_days.days +1 + count_days = strToDate(obj_lines.date_to) - strToDate(obj_lines.date_from) + total_days_of_rec = count_days.days +1 + tot_planned += obj_lines.planned_amount/total_days_of_rec* days_in_period + res[line.id]=tot_planned + else: + res[line.id]=0.00 + return res + + _name = 'account.budget.post.dotation' + _description = "Budget item endowment" + _columns = { + 'name': fields.char('Name', size=64), + 'post_id': fields.many2one('account.budget.post', 'Item', select=True), + 'period_id': fields.many2one('account.period', 'Period'), +# 'quantity': fields.float('Quantity', digits=(16,2)), + 'amount': fields.float('Amount', digits=(16,2)), + 'tot_planned':fields.function(_tot_planned,method=True, string='Total Planned Amount',type='float',store=True), + } + +account_budget_post_dotation() +#=== class crossovered_budget(osv.osv): _name = "crossovered.budget" @@ -138,48 +208,50 @@ class crossovered_budget_lines(osv.osv): } crossovered_budget_lines() -class account_budget_post(osv.osv): - _name = 'account.budget.post' - _inherit = 'account.budget.post' - _columns = { - 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'general_budget_id', 'Budget Lines'), - } -account_budget_post() -class account_budget_post_dotation(osv.osv): - _name = 'account.budget.post.dotation' - _inherit = 'account.budget.post.dotation' - def _tot_planned(self, cr, uid, ids,name,args,context): - res={} - for line in self.browse(cr, uid, ids): - if line.period_id: - obj_period=self.pool.get('account.period').browse(cr, uid,line.period_id.id) - - total_days=strToDate(obj_period.date_stop) - strToDate(obj_period.date_start) - budget_id=line.post_id and line.post_id.id or False - query="select id from crossovered_budget_lines where general_budget_id= '"+ str(budget_id) + "' AND (date_from >='" +obj_period.date_start +"' and date_from <= '"+obj_period.date_stop + "') OR (date_to >='" +obj_period.date_start +"' and date_to <= '"+obj_period.date_stop + "') OR (date_from <'" +obj_period.date_start +"' and date_to > '"+obj_period.date_stop + "')" - cr.execute(query) - res1=cr.fetchall() - - tot_planned=0.00 - for record in res1: - obj_lines = self.pool.get('crossovered.budget.lines').browse(cr, uid,record[0]) - count_days = min(strToDate(obj_period.date_stop),strToDate(obj_lines.date_to)) - max(strToDate(obj_period.date_start), strToDate(obj_lines.date_from)) - days_in_period = count_days.days +1 - count_days = strToDate(obj_lines.date_to) - strToDate(obj_lines.date_from) - total_days_of_rec = count_days.days +1 - tot_planned += obj_lines.planned_amount/total_days_of_rec* days_in_period - res[line.id]=tot_planned - else: - res[line.id]=0.00 - return res - - _columns = { - 'tot_planned':fields.function(_tot_planned,method=True, string='Total Planned Amount',type='float',store=True), - } - -account_budget_post_dotation() +#class account_budget_post(osv.osv): #old code +# _name = 'account.budget.post' +# _inherit = 'account.budget.post' +# _columns = { +# 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'general_budget_id', 'Budget Lines'), +# } +#account_budget_post() +# +#class account_budget_post_dotation(osv.osv): +# _name = 'account.budget.post.dotation' +# _inherit = 'account.budget.post.dotation' +# +# def _tot_planned(self, cr, uid, ids,name,args,context): +# res={} +# for line in self.browse(cr, uid, ids): +# if line.period_id: +# obj_period=self.pool.get('account.period').browse(cr, uid,line.period_id.id) +# +# total_days=strToDate(obj_period.date_stop) - strToDate(obj_period.date_start) +# budget_id=line.post_id and line.post_id.id or False +# query="select id from crossovered_budget_lines where general_budget_id= '"+ str(budget_id) + "' AND (date_from >='" +obj_period.date_start +"' and date_from <= '"+obj_period.date_stop + "') OR (date_to >='" +obj_period.date_start +"' and date_to <= '"+obj_period.date_stop + "') OR (date_from <'" +obj_period.date_start +"' and date_to > '"+obj_period.date_stop + "')" +# cr.execute(query) +# res1=cr.fetchall() +# +# tot_planned=0.00 +# for record in res1: +# obj_lines = self.pool.get('crossovered.budget.lines').browse(cr, uid,record[0]) +# count_days = min(strToDate(obj_period.date_stop),strToDate(obj_lines.date_to)) - max(strToDate(obj_period.date_start), strToDate(obj_lines.date_from)) +# days_in_period = count_days.days +1 +# count_days = strToDate(obj_lines.date_to) - strToDate(obj_lines.date_from) +# total_days_of_rec = count_days.days +1 +# tot_planned += obj_lines.planned_amount/total_days_of_rec* days_in_period +# res[line.id]=tot_planned +# else: +# res[line.id]=0.00 +# return res +# +# _columns = { +# 'tot_planned':fields.function(_tot_planned,method=True, string='Total Planned Amount',type='float',store=True), +# } +# +#account_budget_post_dotation() class account_analytic_account(osv.osv): _name = 'account.analytic.account' @@ -191,6 +263,52 @@ class account_analytic_account(osv.osv): account_analytic_account() +#-------------------------------------------------------------- +# moved from account/project/project.py +# --------------------------------------------------------- +# Budgets +# --------------------------------------------------------- + +#class account_analytic_budget_post(osv.osv): +# _name = 'account.analytic.budget.post' +# _description = 'Budget item' +# _columns = { +# 'code': fields.char('Code', size=64, required=True), +# 'name': fields.char('Name', size=256, required=True), +# 'sens': fields.selection( [('charge','Charge'), ('produit','Product')], 'Direction', required=True), +# 'dotation_ids': fields.one2many('account.analytic.budget.post.dotation', 'post_id', 'Expenses'), +# 'account_ids': fields.many2many('account.analytic.account', 'account_analytic_budget_rel', 'budget_id', 'account_id', 'Accounts'), +# } +# _defaults = { +# 'sens': lambda *a: 'produit', +# } +# +# def spread(self, cr, uid, ids, fiscalyear_id=False, quantity=0.0, amount=0.0): +# +# dobj = self.pool.get('account.analytic.budget.post.dotation') +# for o in self.browse(cr, uid, ids): +# # delete dotations for this post +# dobj.unlink(cr, uid, dobj.search(cr, uid, [('post_id','=',o.id)])) +# +# # create one dotation per period in the fiscal year, and spread the total amount/quantity over those dotations +# fy = self.pool.get('account.fiscalyear').browse(cr, uid, [fiscalyear_id])[0] +# num = len(fy.period_ids) +# for p in fy.period_ids: +# dobj.create(cr, uid, {'post_id': o.id, 'period_id': p.id, 'quantity': quantity/num, 'amount': amount/num}) +# return True +#account_analytic_budget_post() +# +#class account_analytic_budget_post_dotation(osv.osv): +# _name = 'account.analytic.budget.post.dotation' +# _description = "Budget item endowment" +# _columns = { +# 'name': fields.char('Name', size=64), +# 'post_id': fields.many2one('account.analytic.budget.post', 'Item', select=True), +# 'period_id': fields.many2one('account.period', 'Period'), +# 'quantity': fields.float('Quantity', digits=(16,2)), +# 'amount': fields.float('Amount', digits=(16,2)), +# } +#account_analytic_budget_post_dotation() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_budget_crossover/crossovered_budget_report.xml b/addons/account_budget_crossover/crossovered_budget_report.xml index 5fd907d03b1..facfa04b1df 100644 --- a/addons/account_budget_crossover/crossovered_budget_report.xml +++ b/addons/account_budget_crossover/crossovered_budget_report.xml @@ -40,5 +40,15 @@ rml="account_budget_crossover/report/analytic_account_budget_report.rml" auto="False" menu="False"/> + + + + diff --git a/addons/account_budget_crossover/crossovered_budget_view.xml b/addons/account_budget_crossover/crossovered_budget_view.xml index 613d9edf960..178f8dd0696 100644 --- a/addons/account_budget_crossover/crossovered_budget_view.xml +++ b/addons/account_budget_crossover/crossovered_budget_view.xml @@ -1,6 +1,164 @@ + + + Budgets + account.budget.post + tree + + + + + + + account.budget.post.tree + account.budget.post + tree + + + + + + + + + account.budget.post.dotation.form + account.budget.post.dotation + form + +
+ + + + + +
+ + account.budget.post.dotation.tree + account.budget.post.dotation + tree + + + + + + + + + + + Master Budgets + account.budget.post + form + + + + + + + + + + + + account.budget.post.form.inherit + account.budget.post + form + +
+ + + + + + +