Merge lp:~openbig/bigconsulting/ending_balance into lp:bigconsulting

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 109
Proposed branch: lp:~openbig/bigconsulting/ending_balance
Merge into: lp:bigconsulting
Diff against target: 320 lines (+113/-31)
3 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+58/-6)
account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+50/-24)
account_invoice_cash_discount/wizard/invoice_statement_payment.py (+5/-1)
To merge this branch: bzr merge lp:~openbig/bigconsulting/ending_balance
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+36537@code.launchpad.net

Description of the change

Improvement for the Ending Balance

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py'
--- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-09-23 15:13:30 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-09-24 09:43:39 +0000
@@ -645,6 +645,43 @@
645class account_bank_statement(osv.osv):645class account_bank_statement(osv.osv):
646 _inherit="account.bank.statement"646 _inherit="account.bank.statement"
647647
648 def _end_balance(self, cursor, user, ids, name, attr, context=None):
649 res_currency_obj = self.pool.get('res.currency')
650 res_users_obj = self.pool.get('res.users')
651
652 res = {}
653
654 company_currency_id = res_users_obj.browse(cursor, user, user,
655 context=context).company_id.currency_id.id
656 statements = self.browse(cursor, user, ids, context=context)
657 for statement in statements:
658 res[statement.id] = statement.balance_start
659 currency_id = statement.currency.id
660 for line in statement.move_line_ids:
661 if line.debit > 0:
662 if line.account_id.id == \
663 statement.journal_id.default_debit_account_id.id:
664 res[statement.id] += res_currency_obj.compute(cursor,
665 user, company_currency_id, currency_id,
666 line.debit, context=context)
667 else:
668 if line.account_id.id == \
669 statement.journal_id.default_credit_account_id.id:
670 res[statement.id] -= res_currency_obj.compute(cursor,
671 user, company_currency_id, currency_id,
672 line.credit, context=context)
673 if statement.state == 'draft':
674 for line in statement.line_ids:
675 res[statement.id] += line.amount - line.cash_discount
676
677 for r in res:
678 res[r] = round(res[r], 2)
679 return res
680
681 _columns = {
682 'balance_end': fields.function(_end_balance, method=True, string='Balance'),
683 }
684
648 def button_confirm(self, cr, uid, ids, context={}):685 def button_confirm(self, cr, uid, ids, context={}):
649 done = []686 done = []
650 tax_obj = self.pool.get('account.tax')687 tax_obj = self.pool.get('account.tax')
@@ -884,7 +921,7 @@
884 'amount_currency': 0.0,921 'amount_currency': 0.0,
885 'currency_id': currency_id,922 'currency_id': currency_id,
886 }, context=context)923 }, context=context)
887 924
888 currency_diff2 = account_move_line_obj.create(cr, uid, {925 currency_diff2 = account_move_line_obj.create(cr, uid, {
889 'name': move.name,926 'name': move.name,
890 'date': move.date,927 'date': move.date,
@@ -920,7 +957,7 @@
920 'amount_currency': 0.0,957 'amount_currency': 0.0,
921 'currency_id': currency_id,958 'currency_id': currency_id,
922 }, context=context)959 }, context=context)
923 960
924 currency_diff2 = account_move_line_obj.create(cr, uid, {961 currency_diff2 = account_move_line_obj.create(cr, uid, {
925 'name': move.name,962 'name': move.name,
926 'date': move.date,963 'date': move.date,
@@ -939,15 +976,14 @@
939 976
940 if move_line_data.invoice.currency_id.id != company_currency_id:977 if move_line_data.invoice.currency_id.id != company_currency_id:
941 torec.append(currency_diff1)978 torec.append(currency_diff1)
942 979
943 new_end_value += amount+st_tax_amount-newline_sum980 new_end_value += amount+st_tax_amount-newline_sum
944
945 if st.currency.id <> company_currency_id:981 if st.currency.id <> company_currency_id:
946 amount_currency = res_currency_obj.compute(cr, uid, company_currency_id, st.currency.id,982 amount_currency = res_currency_obj.compute(cr, uid, company_currency_id, st.currency.id,
947 (amount+st_tax_amount-newline_sum), context=context,983 (amount+st_tax_amount-newline_sum), context=context,
948 account=acc_cur)984 account=acc_cur)
949 currency_id = st.currency.id985 currency_id = st.currency.id
950986
951 account_move_line_obj.create(cr, uid, {987 account_move_line_obj.create(cr, uid, {
952 'name': move.name,988 'name': move.name,
953 'date': move.date,989 'date': move.date,
@@ -964,10 +1000,10 @@
964 'currency_id': currency_id,1000 'currency_id': currency_id,
965 }, context=context)1001 }, context=context)
9661002
1003
967 account_move_line_obj.write(cr, uid, [x.id for x in1004 account_move_line_obj.write(cr, uid, [x.id for x in
968 account_move_obj.browse(cr, uid, move_id,1005 account_move_obj.browse(cr, uid, move_id,
969 context=context).line_id], {'statement_id': st.id,})1006 context=context).line_id], {'statement_id': st.id,})
970
971 for line in account_move_line_obj.browse(cr, uid, [x.id for x in1007 for line in account_move_line_obj.browse(cr, uid, [x.id for x in
972 account_move_obj.browse(cr, uid, move_id,1008 account_move_obj.browse(cr, uid, move_id,
973 context=context).line_id],1009 context=context).line_id],
@@ -976,6 +1012,7 @@
976 if line.state <> 'valid':1012 if line.state <> 'valid':
977 raise osv.except_osv(_('Error !'),1013 raise osv.except_osv(_('Error !'),
978 _('Account move line "%s" is not valid') % line.name)1014 _('Account move line "%s" is not valid') % line.name)
1015
979 if move.reconcile_id and move.reconcile_id.line_ids:1016 if move.reconcile_id and move.reconcile_id.line_ids:
980 torec += map(lambda x: x.id, move.reconcile_id.line_ids)1017 torec += map(lambda x: x.id, move.reconcile_id.line_ids)
981 #try:1018 #try:
@@ -998,7 +1035,13 @@
998 #### to write the balace value in the ending balance1035 #### to write the balace value in the ending balance
999 balance_end_value = 0.01036 balance_end_value = 0.0
1000 balance_start_value = self.browse(cr, uid, st.id, context=context).balance_start1037 balance_start_value = self.browse(cr, uid, st.id, context=context).balance_start
1038
1039 if st.currency.id <> company_currency_id:
1040 new_end_value = res_currency_obj.compute(cr, uid, company_currency_id, st.currency.id,
1041 new_end_value, context=context,
1042 account=acc_cur)
1001 balance_end_value = balance_start_value + new_end_value1043 balance_end_value = balance_start_value + new_end_value
1044
1002 self.write(cr, uid, done, {'state':'confirm','balance_end_real':balance_end_value}, context=context)1045 self.write(cr, uid, done, {'state':'confirm','balance_end_real':balance_end_value}, context=context)
10031046
1004 return True1047 return True
@@ -1012,6 +1055,9 @@
1012 'tax_type': fields.selection([('tax_included','Tax included'),1055 'tax_type': fields.selection([('tax_included','Tax included'),
1013 ('tax_excluded','Tax excluded')],1056 ('tax_excluded','Tax excluded')],
1014 'Tax method', required=True,),1057 'Tax method', required=True,),
1058 'cash_discount': fields.float('Cash Discount'),
1059 'transferred_amount': fields.float('Transferred'),
1060
1015 }1061 }
1016 1062
1017 def onchange_account_id(self, cr, uid, ids, account_id, context=None):1063 def onchange_account_id(self, cr, uid, ids, account_id, context=None):
@@ -1026,7 +1072,13 @@
1026 result['tax_id'] = False1072 result['tax_id'] = False
10271073
1028 return {'value': result}1074 return {'value': result}
1075
1076 def onchange_cash_discount(self, cr, uid, ids, amount, cash_discount, context=None):
1077 return {'value': {'transferred_amount': amount - cash_discount}}
1029 1078
1079 def onchange_transferred_amount(self, cr, uid, ids, amount, transferred_amount, context=None):
1080 return {'value': {'cash_discount': amount - transferred_amount}}
1081
1030 def onchange_type(self, cr, uid, ids, type, context=None):1082 def onchange_type(self, cr, uid, ids, type, context=None):
1031 result={}1083 result={}
1032 tax_id = self.pool.get('account.tax').search(cr, uid, [])1084 tax_id = self.pool.get('account.tax').search(cr, uid, [])
10331085
=== modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml'
--- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-08-11 12:51:31 +0000
+++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-09-24 09:43:39 +0000
@@ -46,27 +46,27 @@
46 </field>46 </field>
47 </record>47 </record>
4848
49 <record id="bank_statement_form_view1" model="ir.ui.view">49 <record id="bank_statement_form_view1" model="ir.ui.view">
50 <field name="name">account.bank.statement.form</field>50 <field name="name">account.bank.statement.form</field>
51 <field name="model">account.bank.statement</field>51 <field name="model">account.bank.statement</field>
52 <field name="type">form</field>52 <field name="type">form</field>
53 <field name="inherit_id" ref="account.view_bank_statement_form"/>53 <field name="inherit_id" ref="account.view_bank_statement_form"/>
54 <field name="arch" type="xml">54 <field name="arch" type="xml">
55 <xpath expr="//button[@string='Import Invoice']" position="replace">55 <xpath expr="//button[@string='Import Invoice']" position="replace">
56 <button name="%(wizard_populate_statement_from_inv1)d" type="action" string="Import Invoice" attrs="{'invisible':[('state','=','confirm')]}"/>56 <button name="%(wizard_populate_statement_from_inv1)d" type="action" string="Import Invoice" attrs="{'invisible':[('state','=','confirm')]}"/>
57 </xpath>57 </xpath>
58 </field>58 </field>
59 </record>59 </record>
6060
61 <record id="bank_statement_reconcile_form_view1" model="ir.ui.view">61 <record id="bank_statement_reconcile_form_view1" model="ir.ui.view">
62 <field name="name">account.bank.statement.reconcile.form</field>62 <field name="name">account.bank.statement.reconcile.form</field>
63 <field name="model">account.bank.statement.reconcile</field>63 <field name="model">account.bank.statement.reconcile</field>
64 <field name="type">form</field>64 <field name="type">form</field>
65 <field name="inherit_id" ref="account.view_bank_statement_reconcile"/>65 <field name="inherit_id" ref="account.view_bank_statement_reconcile"/>
66 <field name="arch" type="xml">66 <field name="arch" type="xml">
67 <field name="total_new" position="replace">67 <field name="total_new" position="replace">
68 <field name="total_new" string="Total Write Off / Cash Discount"/>68 <field name="total_new" string="Total Write Off / Cash Discount"/>
69 </field>69 </field>
70 </field>70 </field>
71 </record>71 </record>
72 72
@@ -92,13 +92,13 @@
92 <field name="type">form</field>92 <field name="type">form</field>
93 <field name="inherit_id" ref="account.view_bank_statement_reconcile"/>93 <field name="inherit_id" ref="account.view_bank_statement_reconcile"/>
94 <field name="arch" type="xml">94 <field name="arch" type="xml">
95 <xpath expr="//tree[@string='Write-Off']" position="replace">95 <xpath expr="//tree[@string='Write-Off']" position="replace">
96 <tree editable="bottom" string="Write-Off and Cash-Discount">96 <tree editable="bottom" string="Write-Off and Cash-Discount">
97 <field name="account_id" domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]"/>97 <field name="account_id" domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]"/>
98 <field name="amount"/>98 <field name="amount"/>
99 <field name="name"/>99 <field name="name"/>
100 </tree>100 </tree>
101 </xpath>101 </xpath>
102 </field>102 </field>
103 </record>103 </record>
104104
@@ -108,10 +108,10 @@
108 <field name="type">form</field>108 <field name="type">form</field>
109 <field name="inherit_id" ref="account.view_payment_term_line_form"/>109 <field name="inherit_id" ref="account.view_payment_term_line_form"/>
110 <field name="arch" type="xml">110 <field name="arch" type="xml">
111 <field name="days2" position="after">111 <field name="days2" position="after">
112 <field name="compl_cash_discount"/>112 <field name="compl_cash_discount"/>
113 <field name="day_tolerance" required="1" />113 <field name="day_tolerance" required="1" />
114 </field>114 </field>
115 </field>115 </field>
116 </record>116 </record>
117117
@@ -143,25 +143,25 @@
143 </group>143 </group>
144 </form>144 </form>
145 </field>145 </field>
146 </record>146 </record>
147147
148 <record id="action_res_company_wizard" model="ir.actions.act_window">148 <record id="action_res_company_wizard" model="ir.actions.act_window">
149 <field name="name">Account set in Company</field>149 <field name="name">Account set in Company</field>
150 <field name="type">ir.actions.act_window</field>150 <field name="type">ir.actions.act_window</field>
151 <field name="res_model">res.company.wizard</field>151 <field name="res_model">res.company.wizard</field>
152 <field name="view_type">form</field>152 <field name="view_type">form</field>
153 <field name="view_mode">form</field>153 <field name="view_mode">form</field>
154 <field name="target">new</field>154 <field name="target">new</field>
155 </record>155 </record>
156156
157 <record id="config_wizard_res_company_wizard" model="ir.actions.todo">157 <record id="config_wizard_res_company_wizard" model="ir.actions.todo">
158 <field name="name">Account set in Company</field>158 <field name="name">Account set in Company</field>
159 <field name="note">This Configuration step use to set default Account</field>159 <field name="note">This Configuration step use to set default Account</field>
160 <field name="action_id" ref="action_res_company_wizard"/>160 <field name="action_id" ref="action_res_company_wizard"/>
161 </record>161 </record>
162 162
163 163
164 <record model="ir.ui.view" id="view_bank_statement_reconcile_view122">164 <record model="ir.ui.view" id="view_bank_statement_reconcile_view122">
165 <field name="name">account.bank.statement.reconcile.form</field>165 <field name="name">account.bank.statement.reconcile.form</field>
166 <field name="model">account.bank.statement.reconcile</field>166 <field name="model">account.bank.statement.reconcile</field>
167 <field name="inherit_id" ref="account.view_bank_statement_reconcile" />167 <field name="inherit_id" ref="account.view_bank_statement_reconcile" />
@@ -173,7 +173,7 @@
173 </field>173 </field>
174 </record>174 </record>
175175
176 <record id="view_move_line_tree1" model="ir.ui.view">176 <record id="view_move_line_tree1" model="ir.ui.view">
177 <field name="name">account.move.line.tree</field>177 <field name="name">account.move.line.tree</field>
178 <field name="model">account.move.line</field>178 <field name="model">account.move.line</field>
179 <field name="type">tree</field>179 <field name="type">tree</field>
@@ -194,7 +194,7 @@
194 <field name="type">form</field>194 <field name="type">form</field>
195 <field name="arch" type="xml">195 <field name="arch" type="xml">
196 <field name="account_id" position="replace">196 <field name="account_id" position="replace">
197 <field name="account_id" on_change="onchange_account_id(account_id)"/>197 <field name="account_id" on_change="onchange_account_id(account_id)"/>
198 </field>198 </field>
199 </field>199 </field>
200 </record>200 </record>
@@ -236,6 +236,32 @@
236 </field>236 </field>
237 </field>237 </field>
238 </record>238 </record>
239
240 <record model="ir.ui.view" id="view_bank_statement_tax_tree1">
241 <field name="name">account.bank.statement.tree1</field>
242 <field name="model">account.bank.statement</field>
243 <field name="inherit_id" ref="account.view_bank_statement_form"/>
244 <field name="type">form</field>
245 <field name="arch" type="xml">
246 <xpath expr="//field[@name='line_ids']/tree/field[@name='amount']" position="after">
247 <field name="cash_discount" on_change="onchange_cash_discount(amount,cash_discount)"/>
248 <field name="transferred_amount" on_change="onchange_transferred_amount(amount,transferred_amount)"/>
249 </xpath>
250 </field>
251 </record>
239 252
253 <record model="ir.ui.view" id="view_bank_statement_tax_form1">
254 <field name="name">account.bank.statement.form1</field>
255 <field name="model">account.bank.statement</field>
256 <field name="inherit_id" ref="account.view_bank_statement_form"/>
257 <field name="type">form</field>
258 <field name="arch" type="xml">
259 <xpath expr="//field[@name='line_ids']/form/field[@name='amount']" position="after">
260 <field name="cash_discount" on_change="onchange_cash_discount(amount,cash_discount)"/>
261 <field name="transferred_amount" on_change="onchange_transferred_amount(amount,transferred_amount)"/>
262 </xpath>
263 </field>
264 </record>
265
240 </data>266 </data>
241</openerp>267</openerp>
242268
=== modified file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py'
--- account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-09-21 12:22:46 +0000
+++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-09-24 09:43:39 +0000
@@ -115,7 +115,9 @@
115 obj_inv = pool.get('account.invoice')115 obj_inv = pool.get('account.invoice')
116 tax_obj = pool.get('account.tax')116 tax_obj = pool.get('account.tax')
117 invoice_tax_obj = pool.get("account.invoice.tax")117 invoice_tax_obj = pool.get("account.invoice.tax")
118 118
119 discount = 0.0
120
119 statement = statement_obj.browse(cursor, user, data['id'], context=context)121 statement = statement_obj.browse(cursor, user, data['id'], context=context)
120 # for each selected move lines122 # for each selected move lines
121 for line in line_obj.browse(cursor, user, line_ids, context=context):123 for line in line_obj.browse(cursor, user, line_ids, context=context):
@@ -230,6 +232,8 @@
230 'ref': line.ref,232 'ref': line.ref,
231 'reconcile_id': reconcile_id,233 'reconcile_id': reconcile_id,
232 'date':line_date, #time.strftime('%Y-%m-%d'), #line.date_maturity or,234 'date':line_date, #time.strftime('%Y-%m-%d'), #line.date_maturity or,
235 'cash_discount': discount,
236 'transferred_amount': cal_invoice_amount - discount,
233 }, context=context)237 }, context=context)
234 return {}238 return {}
235 239

Subscribers

People subscribed via source and target branches