Merge lp:~akretion-team/openobject-addons/trunk-payment-term-on-purchase-v4 into lp:openobject-addons
- trunk-payment-term-on-purchase-v4
- Merge into trunk
Proposed by
Alexis de Lattre
Status: | Merged |
---|---|
Merged at revision: | 8195 |
Proposed branch: | lp:~akretion-team/openobject-addons/trunk-payment-term-on-purchase-v4 |
Merge into: | lp:openobject-addons |
Diff against target: |
271 lines (+72/-22) 11 files modified
account/account.py (+6/-1) account/account_invoice.py (+3/-2) account/account_move_line.py (+11/-4) account/demo/account_demo.xml (+16/-0) account/partner.py (+9/-2) account/partner_view.xml (+1/-0) purchase/purchase.py (+14/-7) purchase/purchase_view.xml (+1/-0) purchase/stock.py (+7/-0) purchase/wizard/purchase_line_invoice.py (+1/-5) stock/stock.py (+3/-1) |
To merge this branch: | bzr merge lp:~akretion-team/openobject-addons/trunk-payment-term-on-purchase-v4 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
qdp (OpenERP) | Pending | ||
OpenERP Core Team | Pending | ||
Review via email: mp+118256@code.launchpad.net |
Commit message
Description of the change
This is the fourth version of my merge proposal to add Payment terms on PO. This new merge proposal takes into account all the remarks of Quentin on the 3rd merge proposal : https:/
To post a comment you must log in.
Revision history for this message
Alexis de Lattre (alexis-via) wrote : | # |
- 7010. By Alexis de Lattre
-
Merge with addons/trunk revno 8168.
Adapt demo data to the rename of partner XML IDs in server/trunk.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'account/account.py' |
2 | --- account/account.py 2012-07-25 19:26:32 +0000 |
3 | +++ account/account.py 2012-08-04 22:15:27 +0000 |
4 | @@ -2309,8 +2309,13 @@ |
5 | if not line.partner_id: |
6 | raise osv.except_osv(_('Error !'), _("Maturity date of entry line generated by model line '%s' of model '%s' is based on partner payment term!" \ |
7 | "\nPlease define partner on it!")%(line.name, model.name)) |
8 | - if line.partner_id.property_payment_term: |
9 | + |
10 | + payment_term_id = False |
11 | + if model.journal_id.type in ('purchase', 'purchase_refund') and line.partner_id.property_supplier_payment_term: |
12 | + payment_term_id = line.partner_id.property_supplier_payment_term.id |
13 | + elif line.partner_id.property_payment_term: |
14 | payment_term_id = line.partner_id.property_payment_term.id |
15 | + if payment_term_id: |
16 | pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_maturity) |
17 | if pterm_list: |
18 | pterm_list = [l[0] for l in pterm_list] |
19 | |
20 | === modified file 'account/account_invoice.py' |
21 | --- account/account_invoice.py 2012-07-14 23:18:43 +0000 |
22 | +++ account/account_invoice.py 2012-08-04 22:15:27 +0000 |
23 | @@ -216,7 +216,7 @@ |
24 | 'date_invoice': fields.date('Invoice Date', readonly=True, states={'draft':[('readonly',False)]}, select=True, help="Keep empty to use the current date"), |
25 | 'date_due': fields.date('Due Date', states={'paid':[('readonly',True)], 'open':[('readonly',True)], 'close':[('readonly',True)]}, select=True, |
26 | help="If you use payment terms, the due date will be computed automatically at the generation "\ |
27 | - "of accounting entries. If you keep the payment term and the due date empty, it means direct payment. The payment term may compute several due dates, for example 50% now, 50% in one month."), |
28 | + "of accounting entries. If you want to force a due date, make sure that the payment term is not set on the invoice. If you keep the payment term and the due date empty, it means direct payment."), |
29 | 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True, states={'draft':[('readonly',False)]}), |
30 | 'payment_term': fields.many2one('account.payment.term', 'Payment Term',readonly=True, states={'draft':[('readonly',False)]}, |
31 | help="If you use payment terms, the due date will be computed automatically at the generation "\ |
32 | @@ -468,10 +468,11 @@ |
33 | |
34 | if type in ('out_invoice', 'out_refund'): |
35 | acc_id = p.property_account_receivable.id |
36 | + partner_payment_term = p.property_payment_term and p.property_payment_term.id or False |
37 | else: |
38 | acc_id = p.property_account_payable.id |
39 | + partner_payment_term = p.property_supplier_payment_term and p.property_supplier_payment_term.id or False |
40 | fiscal_position = p.property_account_position and p.property_account_position.id or False |
41 | - partner_payment_term = p.property_payment_term and p.property_payment_term.id or False |
42 | if p.bank_ids: |
43 | bank_id = p.bank_ids[0].id |
44 | |
45 | |
46 | === modified file 'account/account_move_line.py' |
47 | --- account/account_move_line.py 2012-07-19 05:38:03 +0000 |
48 | +++ account/account_move_line.py 2012-08-04 22:15:27 +0000 |
49 | @@ -653,17 +653,24 @@ |
50 | return {'value':val} |
51 | if not date: |
52 | date = datetime.now().strftime('%Y-%m-%d') |
53 | + jt = False |
54 | + if journal: |
55 | + jt = journal_obj.browse(cr, uid, journal).type |
56 | part = partner_obj.browse(cr, uid, partner_id) |
57 | |
58 | - if part.property_payment_term: |
59 | - res = payment_term_obj.compute(cr, uid, part.property_payment_term.id, 100, date) |
60 | + payment_term_id = False |
61 | + if jt and jt in ('purchase', 'purchase_refund') and part.property_supplier_payment_term: |
62 | + payment_term_id = part.property_supplier_payment_term.id |
63 | + elif jt and part.property_payment_term: |
64 | + payment_term_id = part.property_payment_term.id |
65 | + if payment_term_id: |
66 | + res = payment_term_obj.compute(cr, uid, payment_term_id, 100, date) |
67 | if res: |
68 | val['date_maturity'] = res[0][0] |
69 | if not account_id: |
70 | id1 = part.property_account_payable.id |
71 | id2 = part.property_account_receivable.id |
72 | - if journal: |
73 | - jt = journal_obj.browse(cr, uid, journal).type |
74 | + if jt: |
75 | if jt in ('sale', 'purchase_refund'): |
76 | val['account_id'] = fiscal_pos_obj.map_account(cr, uid, part and part.property_account_position or False, id2) |
77 | elif jt in ('purchase', 'sale_refund'): |
78 | |
79 | === modified file 'account/demo/account_demo.xml' |
80 | --- account/demo/account_demo.xml 2012-01-31 13:36:57 +0000 |
81 | +++ account/demo/account_demo.xml 2012-08-04 22:15:27 +0000 |
82 | @@ -131,5 +131,21 @@ |
83 | <record id="base.user_demo" model="res.users"> |
84 | <field name="groups_id" eval="[(4,ref('account.group_account_user'))]"/> |
85 | </record> |
86 | + |
87 | + <!-- Add payment term on some demo partners --> |
88 | + <record id="base.res_partner_agrolait" model="res.partner"> |
89 | + <field name="property_payment_term" ref="account_payment_term_net"/> |
90 | + </record> |
91 | + <record id="base.res_partner_c2c" model="res.partner"> |
92 | + <field name="property_payment_term" ref="account_payment_term"/> |
93 | + <field name="property_supplier_payment_term" ref="account_payment_term"/> |
94 | + </record> |
95 | + <record id="base.res_partner_4" model="res.partner"> |
96 | + <field name="property_supplier_payment_term" ref="account_payment_term_net"/> |
97 | + </record> |
98 | + <record id="base.res_partner_asus" model="res.partner"> |
99 | + <field name="property_supplier_payment_term" ref="account_payment_term"/> |
100 | + </record> |
101 | + |
102 | </data> |
103 | </openerp> |
104 | |
105 | === modified file 'account/partner.py' |
106 | --- account/partner.py 2011-08-24 21:19:43 +0000 |
107 | +++ account/partner.py 2012-08-04 22:15:27 +0000 |
108 | @@ -180,9 +180,16 @@ |
109 | 'account.payment.term', |
110 | type='many2one', |
111 | relation='account.payment.term', |
112 | - string ='Payment Term', |
113 | + string ='Customer Payment Term', |
114 | view_load=True, |
115 | - help="This payment term will be used instead of the default one for the current partner"), |
116 | + help="This payment term will be used instead of the default one for sale orders and customer invoices"), |
117 | + 'property_supplier_payment_term': fields.property( |
118 | + 'account.payment.term', |
119 | + type='many2one', |
120 | + relation='account.payment.term', |
121 | + string ='Supplier Payment Term', |
122 | + view_load=True, |
123 | + help="This payment term will be used instead of the default one for purchase orders and supplier invoices"), |
124 | 'ref_companies': fields.one2many('res.company', 'partner_id', |
125 | 'Companies that refers to partner'), |
126 | 'last_reconciliation_date': fields.datetime('Latest Reconciliation Date', help='Date on which the partner accounting entries were reconciled last time') |
127 | |
128 | === modified file 'account/partner_view.xml' |
129 | --- account/partner_view.xml 2012-07-20 14:18:30 +0000 |
130 | +++ account/partner_view.xml 2012-08-04 22:15:27 +0000 |
131 | @@ -91,6 +91,7 @@ |
132 | </group> |
133 | <group> |
134 | <field name="property_account_payable" groups="account.group_account_invoice"/> |
135 | + <field name="property_supplier_payment_term" widget="selection"/> |
136 | <field name="debit"/> |
137 | </group> |
138 | </group> |
139 | |
140 | === modified file 'purchase/purchase.py' |
141 | --- purchase/purchase.py 2012-07-25 12:07:19 +0000 |
142 | +++ purchase/purchase.py 2012-08-04 22:15:27 +0000 |
143 | @@ -203,6 +203,7 @@ |
144 | 'purchase.order.line': (_get_order, None, 10), |
145 | }, multi="sums",help="The total amount"), |
146 | 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'), |
147 | + 'payment_term': fields.many2one('account.payment.term', 'Payment Term'), |
148 | 'product_id': fields.related('order_line','product_id', type='many2one', relation='product.product', string='Product'), |
149 | 'create_uid': fields.many2one('res.users', 'Responsible'), |
150 | 'company_id': fields.many2one('res.company','Company',required=True,select=1), |
151 | @@ -271,12 +272,17 @@ |
152 | def onchange_partner_id(self, cr, uid, ids, partner_id): |
153 | partner = self.pool.get('res.partner') |
154 | if not partner_id: |
155 | - return {'value':{'fiscal_position': False}} |
156 | + return {'value': { |
157 | + 'fiscal_position': False, |
158 | + 'payment_term': False, |
159 | + }} |
160 | supplier_address = partner.address_get(cr, uid, [partner_id], ['default']) |
161 | supplier = partner.browse(cr, uid, partner_id) |
162 | - pricelist = supplier.property_product_pricelist_purchase.id |
163 | - fiscal_position = supplier.property_account_position and supplier.property_account_position.id or False |
164 | - return {'value':{'pricelist_id': pricelist, 'fiscal_position': fiscal_position}} |
165 | + return {'value': { |
166 | + 'pricelist_id': supplier.property_product_pricelist_purchase.id, |
167 | + 'fiscal_position': supplier.property_account_position and supplier.property_account_position.id or False, |
168 | + 'payment_term': supplier.property_supplier_payment_term.id or False, |
169 | + }} |
170 | |
171 | def view_invoice(self, cr, uid, ids, context=None): |
172 | ''' |
173 | @@ -461,8 +467,8 @@ |
174 | 'journal_id': len(journal_ids) and journal_ids[0] or False, |
175 | 'invoice_line': [(6, 0, inv_lines)], |
176 | 'origin': order.name, |
177 | - 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, |
178 | - 'payment_term': order.partner_id.property_payment_term and order.partner_id.property_payment_term.id or False, |
179 | + 'fiscal_position': order.fiscal_position.id or False, |
180 | + 'payment_term': order.payment_term.id or False, |
181 | 'company_id': order.company_id.id, |
182 | } |
183 | inv_id = inv_obj.create(cr, uid, inv_data, context=context) |
184 | @@ -1074,7 +1080,8 @@ |
185 | 'pricelist_id': pricelist_id, |
186 | 'date_order': purchase_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT), |
187 | 'company_id': procurement.company_id.id, |
188 | - 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False |
189 | + 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False, |
190 | + 'payment_term': partner.property_supplier_payment_term.id or False, |
191 | } |
192 | res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=context) |
193 | self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': res[procurement.id]}) |
194 | |
195 | === modified file 'purchase/purchase_view.xml' |
196 | --- purchase/purchase_view.xml 2012-08-04 14:35:56 +0000 |
197 | +++ purchase/purchase_view.xml 2012-08-04 22:15:27 +0000 |
198 | @@ -252,6 +252,7 @@ |
199 | <group> |
200 | <field name="invoice_method"/> |
201 | <field name="invoiced"/> |
202 | + <field name="payment_term" widget="selection"/> |
203 | <field name="fiscal_position"/> |
204 | <!-- We do not need these fields anymore, the information is in open chatter --> |
205 | <field name="validator" groups="base.group_no_one"/> |
206 | |
207 | === modified file 'purchase/stock.py' |
208 | --- purchase/stock.py 2012-07-16 12:13:10 +0000 |
209 | +++ purchase/stock.py 2012-08-04 22:15:27 +0000 |
210 | @@ -60,6 +60,13 @@ |
211 | invoice_vals = super(stock_picking, self)._prepare_invoice(cr, uid, picking, partner, inv_type, journal_id, context=context) |
212 | if picking.purchase_id: |
213 | invoice_vals['fiscal_position'] = picking.purchase_id.fiscal_position.id |
214 | + invoice_vals['payment_term'] = picking.purchase_id.payment_term.id |
215 | + # Fill the date_due on the invoice, for usability purposes. |
216 | + # Note that when an invoice with a payment term is validated, the |
217 | + # date_due is always recomputed from the invoice date and the payment |
218 | + # term. |
219 | + if picking.purchase_id.payment_term and context.get('date_inv'): |
220 | + invoice_vals['date_due'] = self.pool.get('account.invoice').onchange_payment_term_date_invoice(cr, uid, [], picking.purchase_id.payment_term.id, context.get('date_inv'))['value'].get('date_due') |
221 | return invoice_vals |
222 | |
223 | def get_currency_id(self, cursor, user, picking): |
224 | |
225 | === modified file 'purchase/wizard/purchase_line_invoice.py' |
226 | --- purchase/wizard/purchase_line_invoice.py 2012-07-14 20:51:50 +0000 |
227 | +++ purchase/wizard/purchase_line_invoice.py 2012-08-04 22:15:27 +0000 |
228 | @@ -74,10 +74,6 @@ |
229 | journal_id = account_jrnl_obj.search(cr, uid, [('type', '=', 'purchase')], context=None) |
230 | journal_id = journal_id and journal_id[0] or False |
231 | a = partner.property_account_payable.id |
232 | - if partner and partner.property_payment_term.id: |
233 | - pay_term = partner.property_payment_term.id |
234 | - else: |
235 | - pay_term = False |
236 | inv = { |
237 | 'name': name, |
238 | 'origin': name, |
239 | @@ -89,7 +85,7 @@ |
240 | 'invoice_line': [(6,0,lines_ids)], |
241 | 'currency_id' : orders[0].pricelist_id.currency_id.id, |
242 | 'comment': multiple_order_invoice_notes(orders), |
243 | - 'payment_term': pay_term, |
244 | + 'payment_term': orders[0].payment_term.id, |
245 | 'fiscal_position': partner.property_account_position.id |
246 | } |
247 | inv_id = invoice_obj.create(cr, uid, inv) |
248 | |
249 | === modified file 'stock/stock.py' |
250 | --- stock/stock.py 2012-08-03 07:56:33 +0000 |
251 | +++ stock/stock.py 2012-08-04 22:15:27 +0000 |
252 | @@ -987,8 +987,10 @@ |
253 | partner = self.pool.get('res.partner').browse(cr, uid, partner, context=context) |
254 | if inv_type in ('out_invoice', 'out_refund'): |
255 | account_id = partner.property_account_receivable.id |
256 | + payment_term = partner.property_payment_term.id or False |
257 | else: |
258 | account_id = partner.property_account_payable.id |
259 | + payment_term = partner.property_supplier_payment_term.id or False |
260 | comment = self._get_comment_invoice(cr, uid, picking) |
261 | invoice_vals = { |
262 | 'name': picking.name, |
263 | @@ -997,7 +999,7 @@ |
264 | 'account_id': account_id, |
265 | 'partner_id': partner.id, |
266 | 'comment': comment, |
267 | - 'payment_term': partner.property_payment_term and partner.property_payment_term.id or False, |
268 | + 'payment_term': payment_term, |
269 | 'fiscal_position': partner.property_account_position.id, |
270 | 'date_invoice': context.get('date_inv', False), |
271 | 'company_id': picking.company_id.id, |
I have re-merged with current addons/trunk and I adapted demo data to the rename of partner XML IDs in server/trunk. The runbot is green on the revno 7010 of lp:~akretion-team/openobject-addons/trunk-payment-term-on-purchase-v4
If you need more work on my side to merge it for OpenERP 7.0, please tell me !