← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~akretion-team/sale-wkfl/70-sale-validity-enhanced into lp:sale-wkfl

 

Alexis de Lattre has proposed merging lp:~akretion-team/sale-wkfl/70-sale-validity-enhanced into lp:sale-wkfl.

Requested reviews:
  Sale Core Editors (sale-core-editors)

For more details, see:
https://code.launchpad.net/~akretion-team/sale-wkfl/70-sale-validity-enhanced/+merge/201762

This is a small update to the sale_validity module :

1) Update v7 code style and PEP8

2) Add POT file

3) Add default duration (in days) for sale order validity on res.company. If you leave this value to 0 (which is the default), there won't be a default value for the validity date on the sale order. So, if you upgrade to this new version and you don't change the configuration, the behavior of the module will not change (= safe upgrade).
-- 
https://code.launchpad.net/~akretion-team/sale-wkfl/70-sale-validity-enhanced/+merge/201762
Your team Sale Core Editors is requested to review the proposed merge of lp:~akretion-team/sale-wkfl/70-sale-validity-enhanced into lp:sale-wkfl.
=== modified file 'sale_validity/__openerp__.py'
--- sale_validity/__openerp__.py	2013-11-08 08:42:37 +0000
+++ sale_validity/__openerp__.py	2014-01-15 12:05:13 +0000
@@ -30,10 +30,15 @@
 ========================
 
 Add a validity date on the sales quotation defining
-until when the quotation is valid
+until when the quotation is valid.
+
+A default validity duration (in days) can be configured on the company.
 
 """,
- 'data': ["view/sale_order.xml"],
+ 'data': [
+    "view/sale_order.xml",
+    "view/company_view.xml",
+    ],
  'installable': True,
  'active': False,
  }

=== added directory 'sale_validity/i18n'
=== added file 'sale_validity/i18n/sale_validity.pot'
--- sale_validity/i18n/sale_validity.pot	1970-01-01 00:00:00 +0000
+++ sale_validity/i18n/sale_validity.pot	2014-01-15 12:05:13 +0000
@@ -0,0 +1,57 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#	* sale_validity
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-01-15 11:51+0000\n"
+"PO-Revision-Date: 2014-01-15 11:51+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: sale_validity
+#: view:sale.order:0
+msgid "date_order_change(date_order, date_validity, company_id, context)"
+msgstr ""
+
+#. module: sale_validity
+#: help:sale.order,date_validity:0
+msgid "Define date until when quotation is valid"
+msgstr ""
+
+#. module: sale_validity
+#: field:sale.order,date_validity:0
+msgid "Valid Until"
+msgstr ""
+
+#. module: sale_validity
+#: model:ir.model,name:sale_validity.model_res_company
+msgid "Companies"
+msgstr ""
+
+#. module: sale_validity
+#: field:res.company,default_sale_order_validity_days:0
+msgid "Default Validity of Sale Orders (in days)"
+msgstr ""
+
+#. module: sale_validity
+#: help:res.company,default_sale_order_validity_days:0
+msgid "By default, the validity date of sale orders will be the date of the sale order plus the number of days defined in this field. If the value of this field is 0, the sale orders will not have a validity date by default."
+msgstr ""
+
+#. module: sale_validity
+#: model:ir.model,name:sale_validity.model_sale_order
+msgid "Sales Order"
+msgstr ""
+
+#. module: sale_validity
+#: sql_constraint:res.company:0
+msgid "The value of the field 'Default Validity Duration of Sale Orders' must be positive or 0."
+msgstr ""
+

=== modified file 'sale_validity/model/__init__.py'
--- sale_validity/model/__init__.py	2013-11-08 08:50:45 +0000
+++ sale_validity/model/__init__.py	2014-01-15 12:05:13 +0000
@@ -18,4 +18,5 @@
 #
 ##############################################################################
 
+from . import company
 from . import sale_order

=== added file 'sale_validity/model/company.py'
--- sale_validity/model/company.py	1970-01-01 00:00:00 +0000
+++ sale_validity/model/company.py	2014-01-15 12:05:13 +0000
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2014 Akretion (http://www.akretion.com)
+#    @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+#    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 by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv import fields, orm
+
+
+class res_company(orm.Model):
+    _inherit = "res.company"
+
+    _columns = {
+        'default_sale_order_validity_days': fields.integer(
+            "Default Validity of Sale Orders (in days)",
+            help="By default, the validity date of sale orders will be "
+            "the date of the sale order plus the number of days defined "
+            "in this field. If the value of this field is 0, the sale orders "
+            "will not have a validity date by default."),
+        }
+
+    _sql_constraints = [
+        ('sale_order_validity_days_positive',
+         'CHECK (default_sale_order_validity_days >= 0)',
+         "The value of the field 'Default Validity Duration of Sale Orders' "
+         "must be positive or 0."),
+    ]

=== modified file 'sale_validity/model/sale_order.py'
--- sale_validity/model/sale_order.py	2013-11-08 08:53:18 +0000
+++ sale_validity/model/sale_order.py	2014-01-15 12:05:13 +0000
@@ -17,17 +17,63 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
-from osv import fields, osv
-
-
-class sale_order(osv.osv):
+
+from openerp.osv import fields, orm
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
+from datetime import datetime
+from dateutil.relativedelta import relativedelta
+
+
+class sale_order(orm.Model):
     _inherit = "sale.order"
 
-    _columns = {'date_validity': fields.date("Valid Until",
-                                             help="Define date until when quotation is valid",
-                                             readonly=True,
-                                             states={
-                                                 'draft': [('readonly', False)],
-                                                 'sent': [('readonly', True)],
-                                             },
-                                             track_visibility='onchange')}
+    _columns = {
+        'date_validity': fields.date(
+            "Valid Until",
+            help="Define date until when quotation is valid",
+            readonly=True,
+            states={
+                'draft': [('readonly', False)],
+                'sent': [('readonly', True)],
+            },
+            track_visibility='onchange'),
+        }
+
+    def _default_date_validity(self, cr, uid, context=None):
+        date_validity_str = False
+        company_id = self.pool['res.company']._company_default_get(
+            cr, uid, 'sale.order', context=context)
+        company = self.pool['res.company'].browse(
+            cr, uid, company_id, context=context)
+        if company.default_sale_order_validity_days:
+            today_str = fields.date.context_today(
+                self, cr, uid, context=context)
+            today = datetime.strptime(today_str, DEFAULT_SERVER_DATE_FORMAT)
+            date_validity = today + relativedelta(
+                days=company.default_sale_order_validity_days)
+            date_validity_str = date_validity.strftime(
+                DEFAULT_SERVER_DATE_FORMAT)
+        return date_validity_str
+
+    _defaults = {
+        'date_validity': _default_date_validity,
+        }
+
+    def date_order_change(
+            self, cr, uid, ids, date_order, date_validity, company_id,
+            context=None):
+        res = {'value': {}}
+        if date_order:
+            if not company_id:
+                company_id = self.pool['res.company']._company_default_get(
+                    cr, uid, 'sale.order', context=context)
+            company = self.pool['res.company'].browse(
+                cr, uid, company_id, context=context)
+            if company.default_sale_order_validity_days:
+                date_order = datetime.strptime(
+                    date_order, DEFAULT_SERVER_DATE_FORMAT)
+                date_validity = date_order + relativedelta(
+                    days=company.default_sale_order_validity_days)
+                res['value']['date_validity'] = date_validity.strftime(
+                    DEFAULT_SERVER_DATE_FORMAT)
+        return res

=== added file 'sale_validity/view/company_view.xml'
--- sale_validity/view/company_view.xml	1970-01-01 00:00:00 +0000
+++ sale_validity/view/company_view.xml	2014-01-15 12:05:13 +0000
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<openerp>
+<data>
+
+<!--
+    Copyright (C) 2014 Akretion (http://www.akretion.com/)
+    @author: Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+    The licence is in the file __openerp__.py
+-->
+
+<record id="view_company_form" model="ir.ui.view">
+    <field name="name">default.sale.order.validity.company.form</field>
+    <field name="model">res.company</field>
+    <field name="inherit_id" ref="base.view_company_form"/>
+    <field name="arch" type="xml">
+        <xpath expr="//page[@string='Configuration']/group" position="inside">
+            <group name="sale_validity">
+                <field name="default_sale_order_validity_days"/>
+            </group>
+        </xpath>
+    </field>
+</record>
+
+</data>
+</openerp>

=== modified file 'sale_validity/view/sale_order.xml'
--- sale_validity/view/sale_order.xml	2013-02-20 11:27:22 +0000
+++ sale_validity/view/sale_order.xml	2014-01-15 12:05:13 +0000
@@ -5,12 +5,14 @@
     <record id="view_order_form_validity" model="ir.ui.view">
         <field name="name">sale.order.form.validity</field>
         <field name="model">sale.order</field>
-        <field name="type">form</field>
         <field name="inherit_id" ref="sale.view_order_form"/>
         <field name="arch" type="xml">
             <field name="date_order" position="after">
                 <field name="date_validity"/>
             </field>
+            <field name="date_order" position="attributes">
+                <attribute name="on_change">date_order_change(date_order, date_validity, company_id, context)</attribute>
+            </field>
         </field>
     </record>
 


Follow ups