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
1=== modified file 'account/invoice.py'
2--- account/invoice.py 2011-06-21 14:56:58 +0000
3+++ account/invoice.py 2011-10-05 15:03:44 +0000
4@@ -1074,8 +1074,33 @@
5 line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
6 return map(lambda x: (0,0,x), lines)
7
8+ def _hook_fields_for_refund(self, cr, uid, *args):
9+ """
10+ Permits to change fields list to be use for creating invoice refund from an invoice.
11+ """
12+ res = ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id',
13+ 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id']
14+ return res
15+
16+ def _hook_fields_m2o_for_refund(self, cr, uid, *args):
17+ """
18+ Permits to change field that would be use for invoice refund.
19+ NB: This fields should be many2one fields.
20+ """
21+ res = ['address_contact_id', 'address_invoice_id', 'partner_id',
22+ 'account_id', 'currency_id', 'payment_term', 'journal_id']
23+ return res
24+
25+ def _hook_refund_data(self, cr, uid, data, *args):
26+ """
27+ Permits to change data for new refund before their creation
28+ """
29+ if not data:
30+ return False
31+ return data
32+
33 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
34- 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'])
35+ invoices = self.read(cr, uid, ids, self._hook_fields_for_refund(cr, uid))
36 obj_invoice_line = self.pool.get('account.invoice.line')
37 obj_invoice_tax = self.pool.get('account.invoice.tax')
38 obj_journal = self.pool.get('account.journal')
39@@ -1123,9 +1148,9 @@
40 'name': description,
41 })
42 # take the id part of the tuple returned for many2one fields
43- for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
44- 'account_id', 'currency_id', 'payment_term', 'journal_id'):
45+ for field in self._hook_fields_m2o_for_refund(cr, uid):
46 invoice[field] = invoice[field] and invoice[field][0]
47+ invoice = self._hook_refund_data(cr, uid, invoice) or invoice
48 # create the new invoice
49 new_ids.append(self.create(cr, uid, invoice))
50
51
52=== modified file 'account/wizard/account_invoice_refund.py'
53--- account/wizard/account_invoice_refund.py 2011-01-14 00:11:01 +0000
54+++ account/wizard/account_invoice_refund.py 2011-10-05 15:03:44 +0000
55@@ -69,6 +69,29 @@
56 res['fields'][field]['selection'] = journal_select
57 return res
58
59+ def _hook_fields_for_modify_refund(self, cr, uid, *args):
60+ """
61+ Permits to change values that are taken from initial invoice to new invoice(s)
62+ """
63+ res = ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id',
64+ 'partner_insite', 'partner_contact', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line',
65+ 'journal_id', 'period_id']
66+ return res
67+
68+ def _hook_fields_m2o_for_modify_refund(self, cr, uid, *args):
69+ """
70+ Permits to change values for m2o fields taken from initial values to new invoice(s)
71+ """
72+ res = ['address_contact_id', 'address_invoice_id', 'partner_id', 'account_id', 'currency_id', 'payment_term', 'journal_id']
73+ return res
74+
75+ def _hook_create_invoice(self, cr, uid, data, *args):
76+ """
77+ Permits to adapt invoice creation
78+ """
79+ res = inv_obj.create(cr, uid, data, {})
80+ return res
81+
82 def compute_refund(self, cr, uid, ids, mode='refund', context=None):
83 """
84 @param cr: the current row, from the database cursor,
85@@ -165,14 +188,7 @@
86 writeoff_acc_id=inv.account_id.id
87 )
88 if mode == 'modify':
89- invoice = inv_obj.read(cr, uid, [inv.id],
90- ['name', 'type', 'number', 'reference',
91- 'comment', 'date_due', 'partner_id',
92- 'address_contact_id', 'address_invoice_id',
93- 'partner_insite', 'partner_contact',
94- 'partner_ref', 'payment_term', 'account_id',
95- 'currency_id', 'invoice_line', 'tax_line',
96- 'journal_id', 'period_id'], context=context)
97+ invoice = inv_obj.read(cr, uid, [inv.id], self._hook_fields_for_modify_refund(cr, uid), context=context)
98 invoice = invoice[0]
99 del invoice['id']
100 invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)
101@@ -189,10 +205,9 @@
102 'period_id': period,
103 'name': description
104 })
105- for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
106- 'account_id', 'currency_id', 'payment_term', 'journal_id'):
107+ for field in self._hook_fields_m2o_for_modify_refund(cr, uid):
108 invoice[field] = invoice[field] and invoice[field][0]
109- inv_id = inv_obj.create(cr, uid, invoice, {})
110+ inv_id = self._hook_create_invoice(cr, uid, invoice)
111 if inv.payment_term.id:
112 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
113 if 'value' in data and data['value']:
114@@ -217,4 +232,4 @@
115
116 account_invoice_refund()
117
118-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
119\ No newline at end of file
120+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches

to all changes: