Add multi-company support hr_holidays_usability
Add modules hr_holidays_lunch_voucher and hr_holidays_lunch_voucher_natixis
This commit is contained in:
4
hr_holidays_lunch_voucher_natixis/__init__.py
Normal file
4
hr_holidays_lunch_voucher_natixis/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import company
|
||||
from . import wizard
|
||||
20
hr_holidays_lunch_voucher_natixis/__openerp__.py
Normal file
20
hr_holidays_lunch_voucher_natixis/__openerp__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2017 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'HR Holidays Lunch Voucher Natixis',
|
||||
'version': '10.0.1.0.0',
|
||||
'category': 'Human Resources',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Generate order file for Natixis lunch vouchers',
|
||||
'description': '',
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['hr_holidays_lunch_voucher'],
|
||||
'data': [
|
||||
'company_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
15
hr_holidays_lunch_voucher_natixis/company.py
Normal file
15
hr_holidays_lunch_voucher_natixis/company.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2017 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, fields
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
lunch_voucher_natixis_customer_code = fields.Char(
|
||||
string='Natixis Customer Ref', size=7)
|
||||
lunch_voucher_natixis_delivery_code = fields.Char(
|
||||
string='Natixis Delivery Code', size=7)
|
||||
26
hr_holidays_lunch_voucher_natixis/company_view.xml
Normal file
26
hr_holidays_lunch_voucher_natixis/company_view.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2017 Akretion France (www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="view_company_form" model="ir.ui.view">
|
||||
<field name="name">natixis.lunch_voucher.company.form</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="inherit_id" ref="hr_holidays_lunch_voucher.view_company_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<group name="lunch_voucher" position="inside">
|
||||
<field name="lunch_voucher_natixis_customer_code"/>
|
||||
<field name="lunch_voucher_natixis_delivery_code"/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
3
hr_holidays_lunch_voucher_natixis/wizard/__init__.py
Normal file
3
hr_holidays_lunch_voucher_natixis/wizard/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
from . import lunch_voucher_purchase
|
||||
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2017 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, fields, api, _
|
||||
from openerp.exceptions import Warning as UserError
|
||||
|
||||
|
||||
class LunchVoucherPurchase(models.TransientModel):
|
||||
_inherit = 'lunch.voucher.purchase'
|
||||
|
||||
@api.multi
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
action = super(LunchVoucherPurchase, self).run()
|
||||
company = self.env.user.company_id
|
||||
lvao = self.env['lunch.voucher.attribution']
|
||||
assert self._context.get('active_model')\
|
||||
== 'lunch.voucher.attribution', 'wrong source model'
|
||||
assert self._context.get('active_ids'), 'missing active_ids in ctx'
|
||||
if not company.lunch_voucher_natixis_customer_code:
|
||||
raise UserError(_(
|
||||
"Missing Natixis Customer Ref on company '%s'.")
|
||||
% company.name)
|
||||
if not company.lunch_voucher_natixis_delivery_code:
|
||||
raise UserError(_(
|
||||
"Missing Natixis Delivery Code on company '%s'.")
|
||||
% company.name)
|
||||
if len(company.lunch_voucher_natixis_customer_code) != 7:
|
||||
raise UserError(_(
|
||||
"Natixis Customer Ref '%s' on company '%s' should "
|
||||
"have 7 characters/digits.")
|
||||
% (company.lunch_voucher_natixis_customer_code, company.name))
|
||||
if len(company.lunch_voucher_natixis_delivery_code) != 7:
|
||||
raise UserError(_(
|
||||
"Natixis Delivery Code on company '%s' should "
|
||||
"have 7 characters/digits.")
|
||||
% (company.lunch_voucher_natixis_delivery_code, company.name))
|
||||
if not company.lunch_voucher_employer_price:
|
||||
raise UserError(_(
|
||||
"Lunch Voucher Employer Price not set on company '%s'.")
|
||||
% company.name)
|
||||
lvouchers = lvao.browse(self._context['active_ids'])
|
||||
of = u''
|
||||
tmp = {}
|
||||
for lvoucher in lvouchers:
|
||||
if lvoucher.qty > 0:
|
||||
if lvoucher.qty not in tmp:
|
||||
tmp[lvoucher.qty] = 1
|
||||
else:
|
||||
tmp[lvoucher.qty] += 1
|
||||
for vouchers_per_pack, pack_qty in tmp.iteritems():
|
||||
if vouchers_per_pack > 99:
|
||||
raise UserError(_(
|
||||
"Cannot order more than 99 vouchers per pack"))
|
||||
line = u'%s%s%s%s%s%s%s%s\n' % (
|
||||
company.lunch_voucher_natixis_delivery_code,
|
||||
company.lunch_voucher_natixis_customer_code,
|
||||
unicode(pack_qty).zfill(3),
|
||||
unicode(vouchers_per_pack).zfill(2),
|
||||
unicode(pack_qty * vouchers_per_pack).zfill(5),
|
||||
'{:05.2f}'.format(
|
||||
company.lunch_voucher_product_id.standard_price),
|
||||
'{:05.2f}'.format(company.lunch_voucher_employer_price),
|
||||
' ' * 64)
|
||||
of += line
|
||||
today_dt = fields.Date.from_string(
|
||||
fields.Date.context_today(self))
|
||||
filename = 'E%s_%s.txt' % (
|
||||
company.lunch_voucher_natixis_customer_code,
|
||||
today_dt.strftime('%d%m%Y'))
|
||||
self.env['ir.attachment'].create({
|
||||
'name': filename,
|
||||
'res_id': action['res_id'],
|
||||
'res_model': 'purchase.order',
|
||||
'datas': of.encode('base64'),
|
||||
'datas_fname': filename,
|
||||
'type': 'binary',
|
||||
})
|
||||
return action
|
||||
Reference in New Issue
Block a user