Merge lp:~agilebg/account-invoicing/add_module_account_payment_term_month_improvements into lp:~nicolariolini/account-invoicing/add_module_account_payment_term_month

Proposed by Lorenzo Battistini
Status: Merged
Approved by: Nicola Riolini - Micronaet
Approved revision: 48
Merged at revision: 46
Proposed branch: lp:~agilebg/account-invoicing/add_module_account_payment_term_month_improvements
Merge into: lp:~nicolariolini/account-invoicing/add_module_account_payment_term_month
Diff against target: 196 lines (+100/-29)
3 files modified
account_payment_term_month/__openerp__.py (+12/-1)
account_payment_term_month/payment.py (+21/-28)
account_payment_term_month/test/invoice_emission.yml (+67/-0)
To merge this branch: bzr merge lp:~agilebg/account-invoicing/add_module_account_payment_term_month_improvements
Reviewer Review Type Date Requested Status
Nicola Riolini - Micronaet Pending
Review via email: mp+221124@code.launchpad.net
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_payment_term_month/__openerp__.py'
2--- account_payment_term_month/__openerp__.py 2014-03-25 13:27:27 +0000
3+++ account_payment_term_month/__openerp__.py 2014-05-27 17:14:32 +0000
4@@ -2,6 +2,10 @@
5 ##############################################################################
6 #
7 # Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>).
8+# Copyright (C) 2014 Agile Business Group sagl
9+# (<http://www.agilebg.com>)
10+# Copyright (C) 2014 Didotech SRL
11+# (<http://www.didotech.com>)
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Affero General Public License as published
15@@ -25,7 +29,11 @@
16 "website": "http://www.micronaet.it",
17 "category": "Account / Payments",
18 "description": """
19- This module manage commercial month for end of month deadline
20+This module manages commercial month for end of month deadline
21+in payment terms.
22+
23+For instance, if Date=15-01, Number of month=1, Day of Month=-1,
24+then the due date is 28-02
25 """,
26 "depends": [
27 "account",
28@@ -35,6 +43,9 @@
29 "data": [
30 "payment_view.xml",
31 ],
32+ "test": [
33+ "test/invoice_emission.yml",
34+ ],
35 "active": False,
36 "installable": True,
37 }
38
39=== modified file 'account_payment_term_month/payment.py'
40--- account_payment_term_month/payment.py 2014-03-24 12:23:59 +0000
41+++ account_payment_term_month/payment.py 2014-05-27 17:14:32 +0000
42@@ -3,6 +3,8 @@
43 #
44 # OpenERP, Open Source Management Solution
45 # Copyright (C) 2004-2010 Micronaet SRL (<http://www.micronaet.it>).
46+# Copyright (C) 2014 Agile Business Group sagl
47+# (<http://www.agilebg.com>)
48 #
49 # This program is free software: you can redistribute it and/or modify
50 # it under the terms of the GNU Affero General Public License as
51@@ -43,13 +45,13 @@
52 _columns = {
53 'commercial_month': fields.boolean(
54 'Month period',
55- help="If checked"
56- "use the period as a months instead of days (use for"
57+ help="If checked "
58+ "use the period as a months instead of days (use for "
59 "commercial month - end of month payment)"),
60 'months': fields.integer(
61 'Number of month', required=False,
62- help="Number of month to add before computation of the day of"
63- "month. If Date=15-01, Number of month=1, Day of Month=-1,"
64+ help="Number of month to add before computation of the day of "
65+ "month. If Date=15-01, Number of month=1, Day of Month=-1, "
66 "then the due date is 28-02."),
67 }
68 _defaults = {
69@@ -65,13 +67,11 @@
70 _inherit = "account.payment.term"
71
72 def compute(self, cr, uid, id, value, date_ref=False, context=None):
73- ''' Function overrided for check also month values
74- '''
75- if not date_ref:
76- date_ref = datetime.now().strftime('%Y-%m-%d')
77+ '''Function overrided for check also month values'''
78+ results = super(account_payment_term, self).compute(
79+ cr, uid, id, value, date_ref=date_ref, context=context)
80 pt = self.browse(cr, uid, id, context=context)
81 amount = value
82- result = []
83 obj_precision = self.pool.get('decimal.precision')
84 prec = obj_precision.precision_get(cr, uid, 'Account')
85 for line in pt.line_ids:
86@@ -86,23 +86,16 @@
87 next_date = (
88 datetime.strptime(date_ref, '%Y-%m-%d') +
89 relativedelta(months=line.months))
90- else: # days
91- next_date = (
92- datetime.strptime(date_ref, '%Y-%m-%d') +
93- relativedelta(days=line.days))
94- if line.days2 < 0:
95- next_first_date = next_date + relativedelta(
96- day=1, months=1) # Getting 1st of next month
97- next_date = next_first_date + relativedelta(
98- days=line.days2)
99- if line.days2 > 0:
100- next_date += relativedelta(day=line.days2, months=1)
101- result.append((next_date.strftime('%Y-%m-%d'), amt))
102+ if line.days2 < 0:
103+ next_first_date = next_date + relativedelta(
104+ day=1, months=1) # Getting 1st of next month
105+ next_date = next_first_date + relativedelta(
106+ days=line.days2)
107+ if line.days2 > 0:
108+ next_date += relativedelta(day=line.days2, months=1)
109+ results[pt.line_ids.index(line)] = (
110+ next_date.strftime('%Y-%m-%d'),
111+ amt
112+ )
113 amount -= amt
114-
115- amount = reduce(lambda x, y: x+y[1], result, 0.0)
116- dist = round(value-amount, prec)
117- if dist:
118- result.append((time.strftime('%Y-%m-%d'), dist))
119- return result
120-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
121+ return results
122
123=== modified file 'account_payment_term_month/static/src/img/icon.png'
124Binary files account_payment_term_month/static/src/img/icon.png 2014-03-24 12:23:59 +0000 and account_payment_term_month/static/src/img/icon.png 2014-05-27 17:14:32 +0000 differ
125=== added directory 'account_payment_term_month/test'
126=== added file 'account_payment_term_month/test/invoice_emission.yml'
127--- account_payment_term_month/test/invoice_emission.yml 1970-01-01 00:00:00 +0000
128+++ account_payment_term_month/test/invoice_emission.yml 2014-05-27 17:14:32 +0000
129@@ -0,0 +1,67 @@
130+-
131+ I create a account payment term record.
132+-
133+ !record {model: account.payment.term, id: account_payment_term_daysendofmonth0}:
134+ line_ids:
135+ - days: 30
136+ days2: -1
137+ value: balance
138+ name: 30 days end of month
139+-
140+ I create a supplier invoice
141+-
142+ !record {model: account.invoice, id: account_invoice_supplier0, view: account.invoice_supplier_form}:
143+ check_total: 3000.0
144+ date_invoice: !eval "'%s-01-30' %(datetime.now().year)"
145+ invoice_line:
146+ - price_unit: 300.0
147+ product_id: product.product_product_5
148+ quantity: 10.0
149+ journal_id: account.expenses_journal
150+ partner_id: base.res_partner_3
151+ payment_term: account_payment_term_daysendofmonth0
152+ reference_type: none
153+ type: in_invoice
154+-
155+ I change the state of invoice to open by clicking Validate button
156+-
157+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier0}
158+-
159+ I check that payment expiration is wrong at year-03-31
160+-
161+ !assert {model: account.invoice, id: account_invoice_supplier0}:
162+ - date_due == '%s-03-31' %(datetime.now().year)
163+-
164+ I create another end of month payment term with commercial_month
165+-
166+ !record {model: account.payment.term, id: account_payment_term_daysendofmonth1}:
167+ line_ids:
168+ - commercial_month: True
169+ months: 1
170+ days2: -1
171+ value: balance
172+ name: 30 days end of month
173+-
174+ I create an invoice with the commercial_month payment term
175+-
176+ !record {model: account.invoice, id: account_invoice_supplier1, view: account.invoice_supplier_form}:
177+ check_total: 3000.0
178+ date_invoice: !eval "'%s-01-30' %(datetime.now().year)"
179+ invoice_line:
180+ - price_unit: 300.0
181+ product_id: product.product_product_5
182+ quantity: 10.0
183+ journal_id: account.expenses_journal
184+ partner_id: base.res_partner_3
185+ payment_term: account_payment_term_daysendofmonth1
186+ reference_type: none
187+ type: in_invoice
188+-
189+ I change the state of invoice to open by clicking Validate button
190+-
191+ !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier1}
192+-
193+ I check that payment expiration is correct at year-02-28
194+-
195+ !assert {model: account.invoice, id: account_invoice_supplier1}:
196+ - date_due == '%s-02-28' %(datetime.now().year)

Subscribers

People subscribed via source and target branches