2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2010-02-09 05:43:34 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# 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.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# 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
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-02-09 05:43:34 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2009-01-29 22:22:23 +00:00
|
|
|
import os
|
2013-06-11 12:13:10 +00:00
|
|
|
import re
|
2012-07-04 12:57:41 +00:00
|
|
|
import openerp
|
2012-12-17 12:59:02 +00:00
|
|
|
from openerp import SUPERUSER_ID, tools
|
2012-12-10 15:27:23 +00:00
|
|
|
from openerp.osv import fields, osv
|
|
|
|
from openerp.tools.translate import _
|
|
|
|
from openerp.tools.safe_eval import safe_eval as eval
|
2012-12-15 19:26:06 +00:00
|
|
|
from openerp.tools import image_resize_image
|
2013-09-12 12:00:59 +00:00
|
|
|
|
2009-12-09 10:16:28 +00:00
|
|
|
class multi_company_default(osv.osv):
|
|
|
|
"""
|
|
|
|
Manage multi company default value
|
|
|
|
"""
|
|
|
|
_name = 'multi_company.default'
|
|
|
|
_description = 'Default multi company'
|
|
|
|
_order = 'company_id,sequence,id'
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'sequence': fields.integer('Sequence'),
|
2014-05-21 09:52:05 +00:00
|
|
|
'name': fields.char('Name', required=True, help='Name it to easily find a record'),
|
2009-12-09 10:16:28 +00:00
|
|
|
'company_id': fields.many2one('res.company', 'Main Company', required=True,
|
|
|
|
help='Company where the user is connected'),
|
|
|
|
'company_dest_id': fields.many2one('res.company', 'Default Company', required=True,
|
|
|
|
help='Company to store the current record'),
|
|
|
|
'object_id': fields.many2one('ir.model', 'Object', required=True,
|
2010-08-23 15:13:41 +00:00
|
|
|
help='Object affected by this rule'),
|
2014-05-21 09:52:05 +00:00
|
|
|
'expression': fields.char('Expression', required=True,
|
2009-12-23 13:50:03 +00:00
|
|
|
help='Expression, must be True to match\nuse context.get or user (browse)'),
|
2009-12-17 21:37:00 +00:00
|
|
|
'field_id': fields.many2one('ir.model.fields', 'Field', help='Select field property'),
|
2009-12-09 10:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults = {
|
2012-11-02 09:47:05 +00:00
|
|
|
'expression': 'True',
|
|
|
|
'sequence': 100,
|
2009-12-09 10:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def copy(self, cr, uid, id, default=None, context=None):
|
|
|
|
"""
|
|
|
|
Add (copy) in the name when duplicate record
|
|
|
|
"""
|
|
|
|
if not context:
|
|
|
|
context = {}
|
|
|
|
if not default:
|
|
|
|
default = {}
|
|
|
|
company = self.browse(cr, uid, id, context=context)
|
|
|
|
default = default.copy()
|
|
|
|
default['name'] = company.name + _(' (copy)')
|
|
|
|
return super(multi_company_default, self).copy(cr, uid, id, default, context=context)
|
|
|
|
|
|
|
|
multi_company_default()
|
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
class res_company(osv.osv):
|
2008-07-22 14:24:36 +00:00
|
|
|
_name = "res.company"
|
2009-12-09 11:30:34 +00:00
|
|
|
_description = 'Companies'
|
2010-12-10 22:42:58 +00:00
|
|
|
_order = 'name'
|
2013-09-11 06:41:04 +00:00
|
|
|
|
2011-07-04 10:21:15 +00:00
|
|
|
def _get_address_data(self, cr, uid, ids, field_names, arg, context=None):
|
2011-07-06 15:40:01 +00:00
|
|
|
""" Read the 'address' functional fields. """
|
2011-05-12 13:40:15 +00:00
|
|
|
result = {}
|
2011-07-01 13:06:30 +00:00
|
|
|
part_obj = self.pool.get('res.partner')
|
2011-05-12 13:40:15 +00:00
|
|
|
for company in self.browse(cr, uid, ids, context=context):
|
2011-07-04 10:21:15 +00:00
|
|
|
result[company.id] = {}.fromkeys(field_names, False)
|
2011-05-13 07:05:21 +00:00
|
|
|
if company.partner_id:
|
2012-07-04 12:57:41 +00:00
|
|
|
address_data = part_obj.address_get(cr, openerp.SUPERUSER_ID, [company.partner_id.id], adr_pref=['default'])
|
2011-05-13 07:05:21 +00:00
|
|
|
if address_data['default']:
|
2014-07-06 14:44:26 +00:00
|
|
|
address = part_obj.read(cr, openerp.SUPERUSER_ID, [address_data['default']], field_names, context=context)[0]
|
2011-07-04 10:21:15 +00:00
|
|
|
for field in field_names:
|
2011-05-13 07:05:21 +00:00
|
|
|
result[company.id][field] = address[field] or False
|
2011-05-12 13:40:15 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
def _set_address_data(self, cr, uid, company_id, name, value, arg, context=None):
|
2011-07-06 15:40:01 +00:00
|
|
|
""" Write the 'address' functional fields. """
|
2011-05-12 13:40:15 +00:00
|
|
|
company = self.browse(cr, uid, company_id, context=context)
|
2011-05-13 07:05:21 +00:00
|
|
|
if company.partner_id:
|
|
|
|
part_obj = self.pool.get('res.partner')
|
|
|
|
address_data = part_obj.address_get(cr, uid, [company.partner_id.id], adr_pref=['default'])
|
|
|
|
address = address_data['default']
|
|
|
|
if address:
|
2013-02-22 06:27:54 +00:00
|
|
|
part_obj.write(cr, uid, [address], {name: value or False}, context=context)
|
2011-05-13 07:05:21 +00:00
|
|
|
else:
|
2012-02-23 09:37:36 +00:00
|
|
|
part_obj.create(cr, uid, {name: value or False, 'parent_id': company.partner_id.id}, context=context)
|
2011-05-12 13:40:15 +00:00
|
|
|
return True
|
|
|
|
|
2012-12-15 19:26:06 +00:00
|
|
|
def _get_logo_web(self, cr, uid, ids, _field_name, _args, context=None):
|
|
|
|
result = dict.fromkeys(ids, False)
|
|
|
|
for record in self.browse(cr, uid, ids, context=context):
|
|
|
|
size = (180, None)
|
|
|
|
result[record.id] = image_resize_image(record.partner_id.image, size)
|
|
|
|
return result
|
2013-06-11 12:13:10 +00:00
|
|
|
|
2012-12-15 19:26:06 +00:00
|
|
|
def _get_companies_from_partner(self, cr, uid, ids, context=None):
|
|
|
|
return self.pool['res.company'].search(cr, uid, [('partner_id', 'in', ids)], context=context)
|
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
_columns = {
|
2011-12-14 19:57:11 +00:00
|
|
|
'name': fields.related('partner_id', 'name', string='Company Name', size=128, required=True, store=True, type='char'),
|
2008-07-22 14:24:36 +00:00
|
|
|
'parent_id': fields.many2one('res.company', 'Parent Company', select=True),
|
2009-01-26 17:40:29 +00:00
|
|
|
'child_ids': fields.one2many('res.company', 'parent_id', 'Child Companies'),
|
2008-07-22 14:24:36 +00:00
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner', required=True),
|
2012-09-05 15:28:34 +00:00
|
|
|
'rml_header': fields.text('RML Header', required=True),
|
2014-05-21 09:52:05 +00:00
|
|
|
'rml_header1': fields.char('Company Tagline', help="Appears by default on the top right corner of your printed documents (report header)."),
|
2011-07-06 15:40:01 +00:00
|
|
|
'rml_header2': fields.text('RML Internal Header', required=True),
|
2012-07-13 15:35:20 +00:00
|
|
|
'rml_header3': fields.text('RML Internal Header for Landscape Reports', required=True),
|
2012-09-13 12:20:11 +00:00
|
|
|
'rml_footer': fields.text('Report Footer', help="Footer text displayed at the bottom of all reports."),
|
|
|
|
'rml_footer_readonly': fields.related('rml_footer', type='text', string='Report Footer', readonly=True),
|
2012-09-06 13:55:10 +00:00
|
|
|
'custom_footer': fields.boolean('Custom Footer', help="Check this to define the report footer manually. Otherwise it will be filled in automatically."),
|
2014-02-17 13:48:23 +00:00
|
|
|
'font': fields.many2one('res.font', string="Font", domain=[('mode', 'in', ('Normal', 'Regular', 'all', 'Book'))],
|
|
|
|
help="Set the font into the report header, it will be used as default font in the RML reports of the user company"),
|
2012-06-28 08:30:39 +00:00
|
|
|
'logo': fields.related('partner_id', 'image', string="Logo", type="binary"),
|
2012-12-15 19:26:06 +00:00
|
|
|
'logo_web': fields.function(_get_logo_web, string="Logo Web", type="binary", store={
|
|
|
|
'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10),
|
|
|
|
'res.partner': (_get_companies_from_partner, ['image'], 10),
|
|
|
|
}),
|
2008-07-22 14:24:36 +00:00
|
|
|
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
|
2009-12-09 11:18:34 +00:00
|
|
|
'currency_ids': fields.one2many('res.currency', 'company_id', 'Currency'),
|
2010-05-13 11:50:29 +00:00
|
|
|
'user_ids': fields.many2many('res.users', 'res_company_users_rel', 'cid', 'user_id', 'Accepted Users'),
|
2014-05-21 09:52:05 +00:00
|
|
|
'account_no':fields.char('Account No.'),
|
2012-07-04 12:57:41 +00:00
|
|
|
'street': fields.function(_get_address_data, fnct_inv=_set_address_data, size=128, type='char', string="Street", multi='address'),
|
|
|
|
'street2': fields.function(_get_address_data, fnct_inv=_set_address_data, size=128, type='char', string="Street2", multi='address'),
|
|
|
|
'zip': fields.function(_get_address_data, fnct_inv=_set_address_data, size=24, type='char', string="Zip", multi='address'),
|
|
|
|
'city': fields.function(_get_address_data, fnct_inv=_set_address_data, size=24, type='char', string="City", multi='address'),
|
2012-11-29 07:23:34 +00:00
|
|
|
'state_id': fields.function(_get_address_data, fnct_inv=_set_address_data, type='many2one', relation='res.country.state', string="Fed. State", multi='address'),
|
2011-08-15 14:16:43 +00:00
|
|
|
'bank_ids': fields.one2many('res.partner.bank','company_id', 'Bank Accounts', help='Bank accounts related to this company'),
|
2012-07-04 12:57:41 +00:00
|
|
|
'country_id': fields.function(_get_address_data, fnct_inv=_set_address_data, type='many2one', relation='res.country', string="Country", multi='address'),
|
2013-11-30 17:23:19 +00:00
|
|
|
'email': fields.related('partner_id', 'email', size=64, type='char', string="Email", store=True),
|
|
|
|
'phone': fields.related('partner_id', 'phone', size=64, type='char', string="Phone", store=True),
|
2012-07-04 12:57:41 +00:00
|
|
|
'fax': fields.function(_get_address_data, fnct_inv=_set_address_data, size=64, type='char', string="Fax", multi='address'),
|
|
|
|
'website': fields.related('partner_id', 'website', string="Website", type="char", size=64),
|
|
|
|
'vat': fields.related('partner_id', 'vat', string="Tax ID", type="char", size=32),
|
2011-08-18 08:54:34 +00:00
|
|
|
'company_registry': fields.char('Company Registry', size=64),
|
2014-02-17 15:34:59 +00:00
|
|
|
'rml_paper_format': fields.selection([('a4', 'A4'), ('us_letter', 'US Letter')], "Paper Format", required=True, oldname='paper_format'),
|
2010-02-09 05:43:34 +00:00
|
|
|
}
|
2011-07-26 13:21:37 +00:00
|
|
|
_sql_constraints = [
|
2011-09-19 14:48:21 +00:00
|
|
|
('name_uniq', 'unique (name)', 'The company name must be unique !')
|
2011-07-26 13:21:37 +00:00
|
|
|
]
|
2012-08-23 12:41:49 +00:00
|
|
|
|
2012-09-13 12:20:11 +00:00
|
|
|
def onchange_footer(self, cr, uid, ids, custom_footer, phone, fax, email, website, vat, company_registry, bank_ids, context=None):
|
|
|
|
if custom_footer:
|
|
|
|
return {}
|
2012-09-06 13:55:10 +00:00
|
|
|
|
2012-09-13 12:20:11 +00:00
|
|
|
# first line (notice that missing elements are filtered out before the join)
|
|
|
|
res = ' | '.join(filter(bool, [
|
|
|
|
phone and '%s: %s' % (_('Phone'), phone),
|
|
|
|
fax and '%s: %s' % (_('Fax'), fax),
|
|
|
|
email and '%s: %s' % (_('Email'), email),
|
|
|
|
website and '%s: %s' % (_('Website'), website),
|
|
|
|
vat and '%s: %s' % (_('TIN'), vat),
|
|
|
|
company_registry and '%s: %s' % (_('Reg'), company_registry),
|
|
|
|
]))
|
|
|
|
# second line: bank accounts
|
2012-09-10 13:45:33 +00:00
|
|
|
res_partner_bank = self.pool.get('res.partner.bank')
|
2012-09-13 12:20:11 +00:00
|
|
|
account_data = self.resolve_2many_commands(cr, uid, 'bank_ids', bank_ids, context=context)
|
|
|
|
account_names = res_partner_bank._prepare_name_get(cr, uid, account_data, context=context)
|
|
|
|
if account_names:
|
|
|
|
title = _('Bank Accounts') if len(account_names) > 1 else _('Bank Account')
|
|
|
|
res += '\n%s: %s' % (title, ', '.join(name for id, name in account_names))
|
|
|
|
|
|
|
|
return {'value': {'rml_footer': res, 'rml_footer_readonly': res}}
|
2014-07-06 14:44:26 +00:00
|
|
|
|
2012-11-29 07:23:34 +00:00
|
|
|
def onchange_state(self, cr, uid, ids, state_id, context=None):
|
|
|
|
if state_id:
|
2013-05-15 10:58:46 +00:00
|
|
|
return {'value':{'country_id': self.pool.get('res.country.state').browse(cr, uid, state_id, context).country_id.id }}
|
2012-11-29 07:23:34 +00:00
|
|
|
return {}
|
2013-06-11 12:13:10 +00:00
|
|
|
|
2013-06-12 13:32:27 +00:00
|
|
|
def onchange_font_name(self, cr, uid, ids, font, rml_header, rml_header2, rml_header3, context=None):
|
|
|
|
""" To change default header style of all <para> and drawstring. """
|
2013-12-09 13:21:09 +00:00
|
|
|
|
2013-06-11 12:13:10 +00:00
|
|
|
def _change_header(header,font):
|
2013-06-12 13:32:27 +00:00
|
|
|
""" Replace default fontname use in header and setfont tag """
|
|
|
|
|
2013-12-09 13:21:09 +00:00
|
|
|
default_para = re.sub('fontName.?=.?".*"', 'fontName="%s"'% font, header)
|
|
|
|
return re.sub('(<setFont.?name.?=.?)(".*?")(.)', '\g<1>"%s"\g<3>'% font, default_para)
|
2013-12-03 15:41:16 +00:00
|
|
|
|
|
|
|
if not font:
|
|
|
|
return True
|
2013-10-14 09:41:22 +00:00
|
|
|
fontname = self.pool.get('res.font').browse(cr, uid, font, context=context).name
|
2013-06-11 12:13:10 +00:00
|
|
|
return {'value':{
|
2013-12-09 13:21:09 +00:00
|
|
|
'rml_header': _change_header(rml_header, fontname),
|
|
|
|
'rml_header2':_change_header(rml_header2, fontname),
|
|
|
|
'rml_header3':_change_header(rml_header3, fontname)
|
2013-06-11 12:13:10 +00:00
|
|
|
}}
|
|
|
|
|
2012-08-07 10:12:04 +00:00
|
|
|
def on_change_country(self, cr, uid, ids, country_id, context=None):
|
2013-05-15 13:34:50 +00:00
|
|
|
res = {'domain': {'state_id': []}}
|
2012-08-07 12:39:38 +00:00
|
|
|
currency_id = self._get_euro(cr, uid, context=context)
|
|
|
|
if country_id:
|
|
|
|
currency_id = self.pool.get('res.country').browse(cr, uid, country_id, context=context).currency_id.id
|
2013-05-15 13:34:50 +00:00
|
|
|
res['domain'] = {'state_id': [('country_id','=',country_id)]}
|
|
|
|
res['value'] = {'currency_id': currency_id}
|
|
|
|
return res
|
2010-02-09 05:43:34 +00:00
|
|
|
|
2014-03-04 17:52:31 +00:00
|
|
|
def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=100):
|
2014-07-06 14:44:26 +00:00
|
|
|
context = dict(context or {})
|
2014-03-04 17:52:31 +00:00
|
|
|
if context.pop('user_preference', None):
|
2011-03-03 10:52:39 +00:00
|
|
|
# We browse as superuser. Otherwise, the user would be able to
|
|
|
|
# select only the currently visible companies (according to rules,
|
|
|
|
# which are probably to allow to see the child companies) even if
|
|
|
|
# she belongs to some other companies.
|
2012-08-30 15:10:51 +00:00
|
|
|
user = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
|
2010-06-04 00:39:40 +00:00
|
|
|
cmp_ids = list(set([user.company_id.id] + [cmp.id for cmp in user.company_ids]))
|
2014-03-04 17:52:31 +00:00
|
|
|
uid = SUPERUSER_ID
|
|
|
|
args = (args or []) + [('id', 'in', cmp_ids)]
|
|
|
|
return super(res_company, self).name_search(cr, uid, name=name, args=args, operator=operator, context=context, limit=limit)
|
2009-12-09 10:16:28 +00:00
|
|
|
|
2009-12-17 21:37:00 +00:00
|
|
|
def _company_default_get(self, cr, uid, object=False, field=False, context=None):
|
2009-12-09 10:16:28 +00:00
|
|
|
"""
|
|
|
|
Check if the object for this company have a default value
|
|
|
|
"""
|
|
|
|
if not context:
|
|
|
|
context = {}
|
|
|
|
proxy = self.pool.get('multi_company.default')
|
2009-12-17 21:37:00 +00:00
|
|
|
args = [
|
|
|
|
('object_id.model', '=', object),
|
2010-05-04 14:46:42 +00:00
|
|
|
('field_id', '=', field),
|
2015-07-16 12:33:44 +00:00
|
|
|
('company_id', '=', self.pool['res.users']._get_company(cr, uid, context=context)),
|
2009-12-17 21:37:00 +00:00
|
|
|
]
|
2010-05-04 14:46:42 +00:00
|
|
|
|
2015-07-16 12:33:44 +00:00
|
|
|
ids = proxy.search(cr, uid, args, context=context, order='sequence')
|
2012-09-28 17:11:39 +00:00
|
|
|
user = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
|
2009-12-09 10:16:28 +00:00
|
|
|
for rule in proxy.browse(cr, uid, ids, context):
|
|
|
|
if eval(rule.expression, {'context': context, 'user': user}):
|
|
|
|
return rule.company_dest_id.id
|
2012-09-28 16:39:56 +00:00
|
|
|
return user.company_id.id
|
2009-12-09 10:16:28 +00:00
|
|
|
|
2011-06-08 03:03:30 +00:00
|
|
|
@tools.ormcache()
|
2008-07-22 14:24:36 +00:00
|
|
|
def _get_company_children(self, cr, uid=None, company=None):
|
|
|
|
if not company:
|
|
|
|
return []
|
|
|
|
ids = self.search(cr, uid, [('parent_id','child_of',[company])])
|
|
|
|
return ids
|
2011-04-19 06:53:02 +00:00
|
|
|
|
2011-11-07 15:19:49 +00:00
|
|
|
def _get_partner_hierarchy(self, cr, uid, company_id, context=None):
|
2008-07-22 14:24:36 +00:00
|
|
|
if company_id:
|
|
|
|
parent_id = self.browse(cr, uid, company_id)['parent_id']
|
|
|
|
if parent_id:
|
|
|
|
return self._get_partner_hierarchy(cr, uid, parent_id.id, context)
|
|
|
|
else:
|
|
|
|
return self._get_partner_descendance(cr, uid, company_id, [], context)
|
|
|
|
return []
|
|
|
|
|
2011-11-07 15:19:49 +00:00
|
|
|
def _get_partner_descendance(self, cr, uid, company_id, descendance, context=None):
|
2008-07-22 14:24:36 +00:00
|
|
|
descendance.append(self.browse(cr, uid, company_id).partner_id.id)
|
|
|
|
for child_id in self._get_company_children(cr, uid, company_id):
|
|
|
|
if child_id != company_id:
|
|
|
|
descendance = self._get_partner_descendance(cr, uid, child_id, descendance)
|
|
|
|
return descendance
|
|
|
|
|
|
|
|
#
|
|
|
|
# This function restart the cache on the _get_company_children method
|
|
|
|
#
|
2009-01-05 21:17:46 +00:00
|
|
|
def cache_restart(self, cr):
|
2011-06-08 03:03:30 +00:00
|
|
|
self._get_company_children.clear_cache(self)
|
2008-07-22 14:24:36 +00:00
|
|
|
|
2010-08-23 15:13:41 +00:00
|
|
|
def create(self, cr, uid, vals, context=None):
|
|
|
|
if not vals.get('name', False) or vals.get('partner_id', False):
|
|
|
|
self.cache_restart(cr)
|
|
|
|
return super(res_company, self).create(cr, uid, vals, context=context)
|
|
|
|
obj_partner = self.pool.get('res.partner')
|
2012-11-02 16:28:05 +00:00
|
|
|
partner_id = obj_partner.create(cr, uid, {'name': vals['name'], 'is_company':True, 'image': vals.get('logo', False)}, context=context)
|
2010-08-23 15:13:41 +00:00
|
|
|
vals.update({'partner_id': partner_id})
|
2009-01-05 21:17:46 +00:00
|
|
|
self.cache_restart(cr)
|
2010-08-23 15:13:41 +00:00
|
|
|
company_id = super(res_company, self).create(cr, uid, vals, context=context)
|
2013-05-15 09:55:10 +00:00
|
|
|
obj_partner.write(cr, uid, [partner_id], {'company_id': company_id}, context=context)
|
2010-08-23 15:13:41 +00:00
|
|
|
return company_id
|
2008-07-22 14:24:36 +00:00
|
|
|
|
2012-09-10 13:45:33 +00:00
|
|
|
def write(self, cr, uid, ids, values, context=None):
|
2009-01-05 21:17:46 +00:00
|
|
|
self.cache_restart(cr)
|
2012-09-13 12:20:11 +00:00
|
|
|
return super(res_company, self).write(cr, uid, ids, values, context=context)
|
2008-07-22 14:24:36 +00:00
|
|
|
|
2011-11-07 15:19:49 +00:00
|
|
|
def _get_euro(self, cr, uid, context=None):
|
2012-08-20 07:31:45 +00:00
|
|
|
rate_obj = self.pool.get('res.currency.rate')
|
|
|
|
rate_id = rate_obj.search(cr, uid, [('rate', '=', 1)], context=context)
|
|
|
|
return rate_id and rate_obj.browse(cr, uid, rate_id[0], context=context).currency_id.id or False
|
2009-12-09 10:16:28 +00:00
|
|
|
|
2010-05-13 11:50:29 +00:00
|
|
|
def _get_logo(self, cr, uid, ids):
|
2011-09-26 00:54:44 +00:00
|
|
|
return open(os.path.join( tools.config['root_path'], 'addons', 'base', 'res', 'res_company_logo.png'), 'rb') .read().encode('base64')
|
2010-05-13 11:50:29 +00:00
|
|
|
|
2013-10-14 12:38:15 +00:00
|
|
|
def _get_font(self, cr, uid, ids):
|
|
|
|
font_obj = self.pool.get('res.font')
|
2013-12-09 11:05:11 +00:00
|
|
|
res = font_obj.search(cr, uid, [('family', '=', 'Helvetica'), ('mode', '=', 'all')], limit=1)
|
2013-12-09 15:14:54 +00:00
|
|
|
return res and res[0] or False
|
2013-10-14 12:38:15 +00:00
|
|
|
|
2011-06-06 09:43:38 +00:00
|
|
|
_header = """
|
2010-08-24 12:46:39 +00:00
|
|
|
<header>
|
|
|
|
<pageTemplate>
|
2011-06-06 09:43:38 +00:00
|
|
|
<frame id="first" x1="28.0" y1="28.0" width="%s" height="%s"/>
|
2013-05-28 08:59:20 +00:00
|
|
|
<stylesheet>
|
|
|
|
<!-- Set here the default font to use for all <para> tags -->
|
2013-12-09 13:37:42 +00:00
|
|
|
<paraStyle name='Normal' fontName="DejaVuSans"/>
|
2013-05-28 08:59:20 +00:00
|
|
|
</stylesheet>
|
2010-08-24 12:46:39 +00:00
|
|
|
<pageGraphics>
|
|
|
|
<fill color="black"/>
|
|
|
|
<stroke color="black"/>
|
2013-12-09 13:37:42 +00:00
|
|
|
<setFont name="DejaVuSans" size="8"/>
|
2011-06-06 09:43:38 +00:00
|
|
|
<drawString x="%s" y="%s"> [[ formatLang(time.strftime("%%Y-%%m-%%d"), date=True) ]] [[ time.strftime("%%H:%%M") ]]</drawString>
|
2013-12-09 13:37:42 +00:00
|
|
|
<setFont name="DejaVuSans-Bold" size="10"/>
|
2011-06-06 09:43:38 +00:00
|
|
|
<drawCentredString x="%s" y="%s">[[ company.partner_id.name ]]</drawCentredString>
|
2010-08-24 12:46:39 +00:00
|
|
|
<stroke color="#000000"/>
|
2011-06-06 09:43:38 +00:00
|
|
|
<lines>%s</lines>
|
2013-05-28 08:59:20 +00:00
|
|
|
<!-- Set here the default font to use for all <drawString> tags -->
|
|
|
|
<!-- don't forget to change the 2 other occurence of <setFont> above if needed -->
|
2013-12-09 13:37:42 +00:00
|
|
|
<setFont name="DejaVuSans" size="8"/>
|
2010-08-24 12:46:39 +00:00
|
|
|
</pageGraphics>
|
2011-06-06 09:43:38 +00:00
|
|
|
</pageTemplate>
|
2008-07-01 04:05:21 +00:00
|
|
|
</header>"""
|
2011-06-06 09:43:38 +00:00
|
|
|
|
|
|
|
_header2 = _header % (539, 772, "1.0cm", "28.3cm", "11.1cm", "28.3cm", "1.0cm 28.1cm 20.1cm 28.1cm")
|
|
|
|
|
|
|
|
_header3 = _header % (786, 525, 25, 555, 440, 555, "25 550 818 550")
|
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
def _get_header(self,cr,uid,ids):
|
|
|
|
try :
|
2011-01-04 10:13:35 +00:00
|
|
|
header_file = tools.file_open(os.path.join('base', 'report', 'corporate_rml_header.rml'))
|
|
|
|
try:
|
|
|
|
return header_file.read()
|
|
|
|
finally:
|
|
|
|
header_file.close()
|
2008-07-22 14:24:36 +00:00
|
|
|
except:
|
2011-12-21 09:23:44 +00:00
|
|
|
return self._header_a4
|
|
|
|
|
|
|
|
_header_main = """
|
2012-08-24 11:24:34 +00:00
|
|
|
<header>
|
2012-09-05 15:28:34 +00:00
|
|
|
<pageTemplate>
|
|
|
|
<frame id="first" x1="1.3cm" y1="3.0cm" height="%s" width="19.0cm"/>
|
2012-09-10 14:17:29 +00:00
|
|
|
<stylesheet>
|
2013-05-28 08:59:20 +00:00
|
|
|
<!-- Set here the default font to use for all <para> tags -->
|
2013-12-09 13:37:42 +00:00
|
|
|
<paraStyle name='Normal' fontName="DejaVuSans"/>
|
2013-05-28 08:59:20 +00:00
|
|
|
<paraStyle name="main_footer" fontSize="8.0" alignment="CENTER"/>
|
|
|
|
<paraStyle name="main_header" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
|
2012-09-10 14:17:29 +00:00
|
|
|
</stylesheet>
|
2012-09-05 15:28:34 +00:00
|
|
|
<pageGraphics>
|
2013-05-28 08:59:20 +00:00
|
|
|
<!-- Set here the default font to use for all <drawString> tags -->
|
2013-12-09 13:37:42 +00:00
|
|
|
<setFont name="DejaVuSans" size="8"/>
|
2012-09-05 15:28:34 +00:00
|
|
|
<!-- You Logo - Change X,Y,Width and Height -->
|
|
|
|
<image x="1.3cm" y="%s" height="40.0" >[[ company.logo or removeParentNode('image') ]]</image>
|
|
|
|
<fill color="black"/>
|
|
|
|
<stroke color="black"/>
|
|
|
|
|
2012-09-07 10:00:30 +00:00
|
|
|
<!-- page header -->
|
|
|
|
<lines>1.3cm %s 20cm %s</lines>
|
2012-09-05 15:28:34 +00:00
|
|
|
<drawRightString x="20cm" y="%s">[[ company.rml_header1 ]]</drawRightString>
|
|
|
|
<drawString x="1.3cm" y="%s">[[ company.partner_id.name ]]</drawString>
|
2013-01-23 14:38:02 +00:00
|
|
|
<place x="1.3cm" y="%s" height="1.8cm" width="15.0cm">
|
2012-10-03 12:21:30 +00:00
|
|
|
<para style="main_header">[[ display_address(company.partner_id) or '' ]]</para>
|
|
|
|
</place>
|
2012-09-05 15:28:34 +00:00
|
|
|
<drawString x="1.3cm" y="%s">Phone:</drawString>
|
|
|
|
<drawRightString x="7cm" y="%s">[[ company.partner_id.phone or '' ]]</drawRightString>
|
|
|
|
<drawString x="1.3cm" y="%s">Mail:</drawString>
|
|
|
|
<drawRightString x="7cm" y="%s">[[ company.partner_id.email or '' ]]</drawRightString>
|
|
|
|
<lines>1.3cm %s 7cm %s</lines>
|
|
|
|
|
2012-09-07 10:00:30 +00:00
|
|
|
<!-- left margin -->
|
|
|
|
<rotate degrees="90"/>
|
|
|
|
<fill color="grey"/>
|
2014-07-09 11:39:38 +00:00
|
|
|
<drawString x="2.65cm" y="-0.4cm">generated by Odoo.com</drawString>
|
2012-09-07 10:00:30 +00:00
|
|
|
<fill color="black"/>
|
|
|
|
<rotate degrees="-90"/>
|
2012-09-05 15:28:34 +00:00
|
|
|
|
2012-09-07 10:00:30 +00:00
|
|
|
<!--page bottom-->
|
2012-09-05 15:28:34 +00:00
|
|
|
<lines>1.2cm 2.65cm 19.9cm 2.65cm</lines>
|
2012-09-10 14:42:32 +00:00
|
|
|
<place x="1.3cm" y="0cm" height="2.55cm" width="19.0cm">
|
2012-09-10 14:17:29 +00:00
|
|
|
<para style="main_footer">[[ company.rml_footer ]]</para>
|
|
|
|
<para style="main_footer">Contact : [[ user.name ]] - Page: <pageNumber/></para>
|
|
|
|
</place>
|
2012-09-05 15:28:34 +00:00
|
|
|
</pageGraphics>
|
|
|
|
</pageTemplate>
|
2008-04-21 13:04:49 +00:00
|
|
|
</header>"""
|
2011-12-21 09:23:44 +00:00
|
|
|
|
2013-02-15 16:32:14 +00:00
|
|
|
_header_a4 = _header_main % ('21.7cm', '27.7cm', '27.7cm', '27.7cm', '27.8cm', '27.3cm', '25.3cm', '25.0cm', '25.0cm', '24.6cm', '24.6cm', '24.5cm', '24.5cm')
|
|
|
|
_header_letter = _header_main % ('20cm', '26.0cm', '26.0cm', '26.0cm', '26.1cm', '25.6cm', '23.6cm', '23.3cm', '23.3cm', '22.9cm', '22.9cm', '22.8cm', '22.8cm')
|
2011-12-21 09:23:44 +00:00
|
|
|
|
2014-02-12 11:53:50 +00:00
|
|
|
def onchange_rml_paper_format(self, cr, uid, ids, rml_paper_format, context=None):
|
|
|
|
if rml_paper_format == 'us_letter':
|
2011-12-22 15:15:59 +00:00
|
|
|
return {'value': {'rml_header': self._header_letter}}
|
|
|
|
return {'value': {'rml_header': self._header_a4}}
|
2011-12-21 09:23:44 +00:00
|
|
|
|
2013-10-14 09:41:22 +00:00
|
|
|
def act_discover_fonts(self, cr, uid, ids, context=None):
|
2013-12-09 13:21:09 +00:00
|
|
|
return self.pool.get("res.font").font_scan(cr, uid, context=context)
|
2013-10-14 09:41:22 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
_defaults = {
|
|
|
|
'currency_id': _get_euro,
|
2014-02-12 11:53:50 +00:00
|
|
|
'rml_paper_format': 'a4',
|
2008-07-22 14:24:36 +00:00
|
|
|
'rml_header':_get_header,
|
2011-06-06 09:43:38 +00:00
|
|
|
'rml_header2': _header2,
|
|
|
|
'rml_header3': _header3,
|
2013-06-12 13:32:27 +00:00
|
|
|
'logo':_get_logo,
|
2013-10-14 12:38:15 +00:00
|
|
|
'font':_get_font,
|
2008-07-22 14:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_constraints = [
|
2010-12-09 10:57:33 +00:00
|
|
|
(osv.osv._check_recursion, 'Error! You can not create recursive companies.', ['parent_id'])
|
2008-07-22 14:24:36 +00:00
|
|
|
]
|
2007-02-22 07:35:38 +00:00
|
|
|
|
2008-07-23 15:01:27 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|