mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
Add an e-mail reminder for l10n_fr_intrastat_product and l10n_fr_intrastat_service (hope that Akretion France won't forget it's own declarations now !!!) On report.intrastat.product and report.intrastat.service : add copy() fonctions, tracking of important fields, a year_month function field and enhance views. Remove date_done field (the tracking in the chatter does the job). Remove class instanciation in the code.
This commit is contained in:
committed by
Alexis de Lattre
parent
913b208738
commit
6c390713c8
@@ -24,5 +24,6 @@ import country
|
||||
import product
|
||||
import tax
|
||||
import partner
|
||||
import company
|
||||
import intrastat_common
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for
|
||||
'product_view.xml',
|
||||
'country_view.xml',
|
||||
'tax_view.xml',
|
||||
'company_view.xml',
|
||||
'intrastat_menu.xml',
|
||||
],
|
||||
'demo': ['intrastat_demo.xml'],
|
||||
|
||||
61
intrastat_base/company.py
Normal file
61
intrastat_base/company.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Intrastat base module for OpenERP
|
||||
# Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.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 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 osv, orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
class res_company(osv.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
def _compute_intrastat_email_list(self, cr, uid, ids, name, arg, context=None):
|
||||
result = {}
|
||||
for company in self.browse(cr, uid, ids, context=context):
|
||||
result[company.id] = ''
|
||||
for user in company.intrastat_remind_user_ids:
|
||||
if result[company.id]:
|
||||
result[company.id] += ',%s' % (user.email)
|
||||
else:
|
||||
result[company.id] = user.email
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'intrastat_remind_user_ids': fields.many2many('res.users',
|
||||
id1='company_id', id2='user_id',
|
||||
string="Users Receiving the Intrastat Reminder",
|
||||
help="List of OpenERP users who will receive a notification to remind them about the Intrastat declaration."),
|
||||
'intrastat_email_list': fields.function(_compute_intrastat_email_list,
|
||||
type='char', size=1000,
|
||||
string='List of emails of Users Receiving the Intrastat Reminder',
|
||||
help='Comma-separated list of email addresses of Users Receiving the Intrastat Reminder. For use in the email template.'),
|
||||
}
|
||||
|
||||
|
||||
def _check_intrastat_remind_users(self, cr, uid, ids):
|
||||
for company in self.browse(cr, uid, ids):
|
||||
for user in company.intrastat_remind_user_ids:
|
||||
if not user.email:
|
||||
raise orm.except_orm(_('Error :'), _("Missing e-mail address on user '%s'.") %(user.name))
|
||||
return True
|
||||
|
||||
_constraints = [
|
||||
(_check_intrastat_remind_users, "error msg in raise", ['intrastat_remind_user_ids']),
|
||||
]
|
||||
29
intrastat_base/company_view.xml
Normal file
29
intrastat_base/company_view.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="intrastat_company_form" model="ir.ui.view">
|
||||
<field name="name">intrastat.company.form</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="inherit_id" ref="base.view_company_form" />
|
||||
<field name="arch" type="xml">
|
||||
<notebook>
|
||||
<page position="inside" string="Intrastat Settings">
|
||||
<group name="intrastat-common" string="Common Intrastat Settings">
|
||||
<field name="intrastat_remind_user_ids" widget="many2many_tags" />
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -32,4 +32,3 @@ class res_country(osv.Model):
|
||||
'intrastat': False,
|
||||
}
|
||||
|
||||
res_country()
|
||||
|
||||
@@ -24,6 +24,10 @@ from openerp.osv import osv
|
||||
from openerp.tools.translate import _
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class report_intrastat_common(osv.TransientModel):
|
||||
_name = "report.intrastat.common"
|
||||
@@ -41,12 +45,15 @@ class report_intrastat_common(osv.TransientModel):
|
||||
return result
|
||||
|
||||
|
||||
def _compute_end_date(self, cr, uid, ids, object, context=None):
|
||||
def _compute_dates(self, cr, uid, ids, object, context=None):
|
||||
result = {}
|
||||
for intrastat in object.browse(cr, uid, ids, context=context):
|
||||
start_date_datetime = datetime.strptime(intrastat.start_date, '%Y-%m-%d')
|
||||
end_date_str = datetime.strftime(start_date_datetime + relativedelta(day=31), '%Y-%m-%d')
|
||||
result[intrastat.id] = end_date_str
|
||||
result[intrastat.id] = {
|
||||
'end_date': end_date_str,
|
||||
'year_month': start_date_datetime.strftime('%Y-%m'),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
@@ -128,5 +135,16 @@ class report_intrastat_common(osv.TransientModel):
|
||||
result['value'].update({'partner_vat': company['vat']})
|
||||
return result
|
||||
|
||||
report_intrastat_common()
|
||||
|
||||
def send_reminder_email(self, cr, uid, company, module_name, template_xmlid, intrastat_id, context=None):
|
||||
template_data = self.pool['ir.model.data'].get_object_reference(cr, uid, module_name, template_xmlid)
|
||||
if template_data and template_data[0] == 'email.template':
|
||||
template_id = template_data[1]
|
||||
else:
|
||||
raise
|
||||
if company.intrastat_remind_user_ids:
|
||||
self.pool['email.template'].send_mail(cr, uid, template_id, intrastat_id, context=context)
|
||||
logger.info('Intrastat Reminder email has been sent (XMLID: %s).' % template_xmlid)
|
||||
else:
|
||||
logger.warning('The list of users receiving the Intrastat Reminder is empty on company %s' % company.name)
|
||||
return True
|
||||
|
||||
@@ -45,5 +45,3 @@ class product_template(osv.Model):
|
||||
(_check_accessory_cost, "Error msg is in raise", ['is_accessory_cost', 'type'])
|
||||
]
|
||||
|
||||
product_template()
|
||||
|
||||
|
||||
@@ -29,5 +29,3 @@ class account_tax(osv.Model):
|
||||
'exclude_from_intrastat_if_present': fields.boolean('Exclude invoice line from intrastat if this tax is present', help="If this tax is present on an invoice line, this invoice line will be skipped when generating Intrastat Product or Service lines from invoices."),
|
||||
}
|
||||
|
||||
account_tax()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user