diff --git a/intrastat_base/__init__.py b/intrastat_base/__init__.py index c08cbac..f2258f6 100644 --- a/intrastat_base/__init__.py +++ b/intrastat_base/__init__.py @@ -24,5 +24,6 @@ import country import product import tax import partner +import company import intrastat_common diff --git a/intrastat_base/__openerp__.py b/intrastat_base/__openerp__.py index 058b764..973786b 100644 --- a/intrastat_base/__openerp__.py +++ b/intrastat_base/__openerp__.py @@ -46,6 +46,7 @@ Please contact Alexis de Lattre from Akretion for 'product_view.xml', 'country_view.xml', 'tax_view.xml', + 'company_view.xml', 'intrastat_menu.xml', ], 'demo': ['intrastat_demo.xml'], diff --git a/intrastat_base/company.py b/intrastat_base/company.py new file mode 100644 index 0000000..4fc63cb --- /dev/null +++ b/intrastat_base/company.py @@ -0,0 +1,61 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Intrastat base module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +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']), + ] diff --git a/intrastat_base/company_view.xml b/intrastat_base/company_view.xml new file mode 100644 index 0000000..14cf1fe --- /dev/null +++ b/intrastat_base/company_view.xml @@ -0,0 +1,29 @@ + + + + + + + + + intrastat.company.form + res.company + + + + + + + + + + + + + + + diff --git a/intrastat_base/country.py b/intrastat_base/country.py index 38ae403..3315476 100644 --- a/intrastat_base/country.py +++ b/intrastat_base/country.py @@ -32,4 +32,3 @@ class res_country(osv.Model): 'intrastat': False, } -res_country() diff --git a/intrastat_base/intrastat_common.py b/intrastat_base/intrastat_common.py index 622d3d2..fba3a08 100644 --- a/intrastat_base/intrastat_common.py +++ b/intrastat_base/intrastat_common.py @@ -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 diff --git a/intrastat_base/product.py b/intrastat_base/product.py index 894dcbb..640f9ea 100644 --- a/intrastat_base/product.py +++ b/intrastat_base/product.py @@ -45,5 +45,3 @@ class product_template(osv.Model): (_check_accessory_cost, "Error msg is in raise", ['is_accessory_cost', 'type']) ] -product_template() - diff --git a/intrastat_base/tax.py b/intrastat_base/tax.py index 209c2b5..5d37d1b 100644 --- a/intrastat_base/tax.py +++ b/intrastat_base/tax.py @@ -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() -