← Back to team overview

openobject-italia-core-devs team mailing list archive

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

 

Lorenzo Battistini - Agile BG has proposed merging lp:~agilebg/account-invoicing/add_module_account_payment_term_month_improvements into lp:~nicolariolini/account-invoicing/add_module_account_payment_term_month.

Requested reviews:
  Nicola Riolini - Micronaet (nicolariolini)

For more details, see:
https://code.launchpad.net/~agilebg/account-invoicing/add_module_account_payment_term_month_improvements/+merge/221124
-- 
https://code.launchpad.net/~agilebg/account-invoicing/add_module_account_payment_term_month_improvements/+merge/221124
Your team OpenERP Italia core devs is subscribed to branch lp:~nicolariolini/account-invoicing/add_module_account_payment_term_month.
=== modified file 'account_payment_term_month/__openerp__.py'
--- account_payment_term_month/__openerp__.py	2014-03-25 13:27:27 +0000
+++ account_payment_term_month/__openerp__.py	2014-05-27 17:14:32 +0000
@@ -2,6 +2,10 @@
 ##############################################################################
 #
 #    Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>).
+#    Copyright (C) 2014 Agile Business Group sagl
+#    (<http://www.agilebg.com>)
+#    Copyright (C) 2014 Didotech SRL
+#    (<http://www.didotech.com>)
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as published
@@ -25,7 +29,11 @@
     "website": "http://www.micronaet.it";,
     "category": "Account / Payments",
     "description": """
-         This module manage commercial month for end of month deadline
+This module manages commercial month for end of month deadline
+in payment terms.
+
+For instance, if Date=15-01, Number of month=1, Day of Month=-1,
+then the due date is 28-02
     """,
     "depends": [
         "account",
@@ -35,6 +43,9 @@
     "data": [
         "payment_view.xml",
     ],
+    "test": [
+        "test/invoice_emission.yml",
+    ],
     "active": False,
     "installable": True,
 }

=== modified file 'account_payment_term_month/payment.py'
--- account_payment_term_month/payment.py	2014-03-24 12:23:59 +0000
+++ account_payment_term_month/payment.py	2014-05-27 17:14:32 +0000
@@ -3,6 +3,8 @@
 #
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2010 Micronaet SRL (<http://www.micronaet.it>).
+#    Copyright (C) 2014 Agile Business Group sagl
+#    (<http://www.agilebg.com>)
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -43,13 +45,13 @@
     _columns = {
         'commercial_month': fields.boolean(
             'Month period',
-            help="If checked"
-                 "use the period as a months instead of days (use for"
+            help="If checked "
+                 "use the period as a months instead of days (use for "
                  "commercial month - end of month payment)"),
         'months': fields.integer(
             'Number of month', required=False,
-            help="Number of month to add before computation of the day of"
-                 "month. If Date=15-01, Number of month=1, Day of Month=-1,"
+            help="Number of month to add before computation of the day of "
+                 "month. If Date=15-01, Number of month=1, Day of Month=-1, "
                  "then the due date is 28-02."),
     }
     _defaults = {
@@ -65,13 +67,11 @@
     _inherit = "account.payment.term"
 
     def compute(self, cr, uid, id, value, date_ref=False, context=None):
-        ''' Function overrided for check also month values
-        '''
-        if not date_ref:
-            date_ref = datetime.now().strftime('%Y-%m-%d')
+        '''Function overrided for check also month values'''
+        results = super(account_payment_term, self).compute(
+            cr, uid, id, value, date_ref=date_ref, context=context)
         pt = self.browse(cr, uid, id, context=context)
         amount = value
-        result = []
         obj_precision = self.pool.get('decimal.precision')
         prec = obj_precision.precision_get(cr, uid, 'Account')
         for line in pt.line_ids:
@@ -86,23 +86,16 @@
                     next_date = (
                         datetime.strptime(date_ref, '%Y-%m-%d') +
                         relativedelta(months=line.months))
-                else:  # days
-                    next_date = (
-                        datetime.strptime(date_ref, '%Y-%m-%d') +
-                        relativedelta(days=line.days))
-                if line.days2 < 0:
-                    next_first_date = next_date + relativedelta(
-                        day=1, months=1)  # Getting 1st of next month
-                    next_date = next_first_date + relativedelta(
-                        days=line.days2)
-                if line.days2 > 0:
-                    next_date += relativedelta(day=line.days2, months=1)
-                result.append((next_date.strftime('%Y-%m-%d'), amt))
+                    if line.days2 < 0:
+                        next_first_date = next_date + relativedelta(
+                            day=1, months=1)  # Getting 1st of next month
+                        next_date = next_first_date + relativedelta(
+                            days=line.days2)
+                    if line.days2 > 0:
+                        next_date += relativedelta(day=line.days2, months=1)
+                    results[pt.line_ids.index(line)] = (
+                        next_date.strftime('%Y-%m-%d'),
+                        amt
+                        )
                 amount -= amt
-
-        amount = reduce(lambda x, y: x+y[1], result, 0.0)
-        dist = round(value-amount, prec)
-        if dist:
-            result.append((time.strftime('%Y-%m-%d'), dist))
-        return result
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+        return results

=== modified file 'account_payment_term_month/static/src/img/icon.png'
Binary 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
=== added directory 'account_payment_term_month/test'
=== added file 'account_payment_term_month/test/invoice_emission.yml'
--- account_payment_term_month/test/invoice_emission.yml	1970-01-01 00:00:00 +0000
+++ account_payment_term_month/test/invoice_emission.yml	2014-05-27 17:14:32 +0000
@@ -0,0 +1,67 @@
+-
+  I create a account payment term record.
+-
+  !record {model: account.payment.term, id: account_payment_term_daysendofmonth0}:
+    line_ids:
+      - days: 30
+        days2: -1
+        value: balance
+    name: 30 days end of month
+-
+  I create a supplier invoice
+-
+  !record {model: account.invoice, id: account_invoice_supplier0, view: account.invoice_supplier_form}:
+    check_total: 3000.0
+    date_invoice: !eval "'%s-01-30' %(datetime.now().year)"
+    invoice_line:
+      - price_unit: 300.0
+        product_id: product.product_product_5
+        quantity: 10.0
+    journal_id: account.expenses_journal
+    partner_id: base.res_partner_3
+    payment_term: account_payment_term_daysendofmonth0
+    reference_type: none
+    type: in_invoice
+-
+  I change the state of invoice to open by clicking Validate button
+-
+  !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier0}
+- 
+  I check that payment expiration is wrong at year-03-31
+-
+  !assert {model: account.invoice, id: account_invoice_supplier0}:
+    - date_due == '%s-03-31' %(datetime.now().year)
+-
+  I create another end of month payment term with commercial_month
+-
+  !record {model: account.payment.term, id: account_payment_term_daysendofmonth1}:
+    line_ids:
+      - commercial_month: True
+        months: 1
+        days2: -1
+        value: balance
+    name: 30 days end of month
+-
+  I create an invoice with the commercial_month payment term
+-
+  !record {model: account.invoice, id: account_invoice_supplier1, view: account.invoice_supplier_form}:
+    check_total: 3000.0
+    date_invoice: !eval "'%s-01-30' %(datetime.now().year)"
+    invoice_line:
+      - price_unit: 300.0
+        product_id: product.product_product_5
+        quantity: 10.0
+    journal_id: account.expenses_journal
+    partner_id: base.res_partner_3
+    payment_term: account_payment_term_daysendofmonth1
+    reference_type: none
+    type: in_invoice
+-
+  I change the state of invoice to open by clicking Validate button
+-
+  !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_supplier1}
+- 
+  I check that payment expiration is correct at year-02-28
+-
+  !assert {model: account.invoice, id: account_invoice_supplier1}:
+    - date_due == '%s-02-28' %(datetime.now().year)


Follow ups