Skip to content

Commit

Permalink
Update v7 code style and PEP8
Browse files Browse the repository at this point in the history
Add POT file
Add default value duration (in days) for validity per company (ignored if you leave the value to 0, which is the default).
  • Loading branch information
Alexis de Lattre authored and guewen committed Mar 7, 2014
2 parents 0f3db0f + 57af57c commit df14d60
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 13 deletions.
9 changes: 7 additions & 2 deletions sale_validity/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
57 changes: 57 additions & 0 deletions sale_validity/i18n/sale_validity.pot
Original file line number Diff line number Diff line change
@@ -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 ""

1 change: 1 addition & 0 deletions sale_validity/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
#
##############################################################################

from . import company
from . import sale_order
42 changes: 42 additions & 0 deletions sale_validity/model/company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <[email protected]>
#
# 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."),
]
66 changes: 56 additions & 10 deletions sale_validity/model/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,63 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, 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(osv.osv):

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
25 changes: 25 additions & 0 deletions sale_validity/view/company_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<openerp>
<data>

<!--
Copyright (C) 2014 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
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>
4 changes: 3 additions & 1 deletion sale_validity/view/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit df14d60

Please sign in to comment.