Merge lp:~unifield-team/unifield-addons/UF_437_refund_hooks into lp:unifield-addons

Proposed by Olivier DOSSMANN
Status: Merged
Merged at revision: 4502
Proposed branch: lp:~unifield-team/unifield-addons/UF_437_refund_hooks
Merge into: lp:unifield-addons
Diff against target: 120 lines (+55/-15)
2 files modified
account/invoice.py (+28/-3)
account/wizard/account_invoice_refund.py (+27/-12)
To merge this branch: bzr merge lp:~unifield-team/unifield-addons/UF_437_refund_hooks
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+78267@code.launchpad.net

Description of the change

Permit to pass analytic distribution from invoice to refund and from invoice to new invoice in case of "modify" type in refund wizard.

Hooks permits to pass other fields or modify fields that would be taken from initial invoice to make a refund.

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.py'
--- account/invoice.py 2011-06-21 14:56:58 +0000
+++ account/invoice.py 2011-10-05 15:03:44 +0000
@@ -1074,8 +1074,33 @@
1074 line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]1074 line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
1075 return map(lambda x: (0,0,x), lines)1075 return map(lambda x: (0,0,x), lines)
10761076
1077 def _hook_fields_for_refund(self, cr, uid, *args):
1078 """
1079 Permits to change fields list to be use for creating invoice refund from an invoice.
1080 """
1081 res = ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id',
1082 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id']
1083 return res
1084
1085 def _hook_fields_m2o_for_refund(self, cr, uid, *args):
1086 """
1087 Permits to change field that would be use for invoice refund.
1088 NB: This fields should be many2one fields.
1089 """
1090 res = ['address_contact_id', 'address_invoice_id', 'partner_id',
1091 'account_id', 'currency_id', 'payment_term', 'journal_id']
1092 return res
1093
1094 def _hook_refund_data(self, cr, uid, data, *args):
1095 """
1096 Permits to change data for new refund before their creation
1097 """
1098 if not data:
1099 return False
1100 return data
1101
1077 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):1102 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
1078 invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id'])1103 invoices = self.read(cr, uid, ids, self._hook_fields_for_refund(cr, uid))
1079 obj_invoice_line = self.pool.get('account.invoice.line')1104 obj_invoice_line = self.pool.get('account.invoice.line')
1080 obj_invoice_tax = self.pool.get('account.invoice.tax')1105 obj_invoice_tax = self.pool.get('account.invoice.tax')
1081 obj_journal = self.pool.get('account.journal')1106 obj_journal = self.pool.get('account.journal')
@@ -1123,9 +1148,9 @@
1123 'name': description,1148 'name': description,
1124 })1149 })
1125 # take the id part of the tuple returned for many2one fields1150 # take the id part of the tuple returned for many2one fields
1126 for field in ('address_contact_id', 'address_invoice_id', 'partner_id',1151 for field in self._hook_fields_m2o_for_refund(cr, uid):
1127 'account_id', 'currency_id', 'payment_term', 'journal_id'):
1128 invoice[field] = invoice[field] and invoice[field][0]1152 invoice[field] = invoice[field] and invoice[field][0]
1153 invoice = self._hook_refund_data(cr, uid, invoice) or invoice
1129 # create the new invoice1154 # create the new invoice
1130 new_ids.append(self.create(cr, uid, invoice))1155 new_ids.append(self.create(cr, uid, invoice))
11311156
11321157
=== modified file 'account/wizard/account_invoice_refund.py'
--- account/wizard/account_invoice_refund.py 2011-01-14 00:11:01 +0000
+++ account/wizard/account_invoice_refund.py 2011-10-05 15:03:44 +0000
@@ -69,6 +69,29 @@
69 res['fields'][field]['selection'] = journal_select69 res['fields'][field]['selection'] = journal_select
70 return res70 return res
7171
72 def _hook_fields_for_modify_refund(self, cr, uid, *args):
73 """
74 Permits to change values that are taken from initial invoice to new invoice(s)
75 """
76 res = ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id',
77 'partner_insite', 'partner_contact', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line',
78 'journal_id', 'period_id']
79 return res
80
81 def _hook_fields_m2o_for_modify_refund(self, cr, uid, *args):
82 """
83 Permits to change values for m2o fields taken from initial values to new invoice(s)
84 """
85 res = ['address_contact_id', 'address_invoice_id', 'partner_id', 'account_id', 'currency_id', 'payment_term', 'journal_id']
86 return res
87
88 def _hook_create_invoice(self, cr, uid, data, *args):
89 """
90 Permits to adapt invoice creation
91 """
92 res = inv_obj.create(cr, uid, data, {})
93 return res
94
72 def compute_refund(self, cr, uid, ids, mode='refund', context=None):95 def compute_refund(self, cr, uid, ids, mode='refund', context=None):
73 """96 """
74 @param cr: the current row, from the database cursor,97 @param cr: the current row, from the database cursor,
@@ -165,14 +188,7 @@
165 writeoff_acc_id=inv.account_id.id188 writeoff_acc_id=inv.account_id.id
166 )189 )
167 if mode == 'modify':190 if mode == 'modify':
168 invoice = inv_obj.read(cr, uid, [inv.id],191 invoice = inv_obj.read(cr, uid, [inv.id], self._hook_fields_for_modify_refund(cr, uid), context=context)
169 ['name', 'type', 'number', 'reference',
170 'comment', 'date_due', 'partner_id',
171 'address_contact_id', 'address_invoice_id',
172 'partner_insite', 'partner_contact',
173 'partner_ref', 'payment_term', 'account_id',
174 'currency_id', 'invoice_line', 'tax_line',
175 'journal_id', 'period_id'], context=context)
176 invoice = invoice[0]192 invoice = invoice[0]
177 del invoice['id']193 del invoice['id']
178 invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)194 invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)
@@ -189,10 +205,9 @@
189 'period_id': period,205 'period_id': period,
190 'name': description206 'name': description
191 })207 })
192 for field in ('address_contact_id', 'address_invoice_id', 'partner_id',208 for field in self._hook_fields_m2o_for_modify_refund(cr, uid):
193 'account_id', 'currency_id', 'payment_term', 'journal_id'):
194 invoice[field] = invoice[field] and invoice[field][0]209 invoice[field] = invoice[field] and invoice[field][0]
195 inv_id = inv_obj.create(cr, uid, invoice, {})210 inv_id = self._hook_create_invoice(cr, uid, invoice)
196 if inv.payment_term.id:211 if inv.payment_term.id:
197 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)212 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
198 if 'value' in data and data['value']:213 if 'value' in data and data['value']:
@@ -217,4 +232,4 @@
217232
218account_invoice_refund()233account_invoice_refund()
219234
220# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
221\ No newline at end of file235\ No newline at end of file
236# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches

to all changes: