Skip to content

Commit

Permalink
Merge pull request #1 from savoirfairelinux/7.0-remove-dependance-hr_…
Browse files Browse the repository at this point in the history
…expense_line_supplier

Remove dependency on hr_expense_line_supplier. Add partner field, needed it in dependency.
  • Loading branch information
Maxime Chambreuil - http://www.savoirfairelinux.com committed Nov 7, 2014
2 parents 78b1509 + 0eaba56 commit 1f0403f
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 165 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
env:
- VERSION="7.0" ODOO_REPO="odoo/odoo"
- VERSION="7.0" ODOO_REPO="OCA/OCB"
- VERSION="7.0" UNIT_TEST="1"

virtualenv:
system_site_packages: true
Expand All @@ -14,10 +15,11 @@ install:
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
- git clone https://github.com/OCA/l10n-canada ${HOME}/l10n-canada -b ${VERSION}
- sudo pip install num2words

script:
- travis_run_flake8
- travis_run_tests

after_success:
coveralls
- coveralls
2 changes: 1 addition & 1 deletion account_account_halftax/account_account_halftax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="model">account.account</field>
<field name="inherit_id" ref="account.view_account_form"/>
<field name="arch" type="xml">
<field name="code" position="after">
<field name="reconcile" position="after">
<field name="tax_halftax"/>
</field>
</field>
Expand Down
12 changes: 8 additions & 4 deletions account_tax_accountedge/account_tax_accountedge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Odoo, Open Source Management Solution
# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -15,15 +15,19 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.·····
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from osv import orm, fields
from openerp.osv import orm, fields


class account_tax(orm.Model):
_inherit = 'account.tax'
_columns = {
'tax_code_accountedge': fields.char('Tax code in AccountEdge', size=16, required=False),
'tax_code_accountedge': fields.char(
'Tax code in AccountEdge',
size=16,
required=False,
),
}
9 changes: 6 additions & 3 deletions hr_employee_accountedge/hr_employee_accountedge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Odoo, Open Source Management Solution
# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -19,11 +19,14 @@
#
##############################################################################

from osv import fields, orm
from openerp.osv import fields, orm


class hr_employee(orm.Model):
_inherit = 'hr.employee'
_columns = {
'supplier_id_accountedge': fields.char('Supplier ID in AccountEdge', size=16),
'supplier_id_accountedge': fields.char(
'Supplier ID in AccountEdge',
size=16,
),
}
22 changes: 14 additions & 8 deletions hr_expense_accountedge/edi/hr_expense_expense.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Odoo, Open Source Business Applications
# Copyright (c) 2011 OpenERP S.A. <http://openerp.com>
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -22,21 +22,27 @@
from openerp.osv import fields, orm
from edi import EDIMixin

URL = "%s/web/webclient/home#id=%s&view_type=page&model=hr.expense.expense"


class hr_expense_expense(orm.Model, EDIMixin):
_inherit = 'hr.expense.expense'

def _edi_get_web_url_view(self, cr, uid, ids, field_name, arg, context):
res = {}
for id in ids:
web_root_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
res[id] = "%s/web/webclient/home#id=%s&view_type=page&model=hr.expense.expense" % (web_root_url, id)
web_root_url = self.pool.get('ir.config_parameter').get_param(
cr, uid, 'web.base.url',
)
res[id] = URL % (web_root_url, id)
return res

_columns = {
'web_url_view': fields.function(_edi_get_web_url_view,
string='Url of the expense view',
type='char',
size=255,
readonly=True),
'web_url_view': fields.function(
_edi_get_web_url_view,
string='Url of the expense view',
type='char',
size=255,
readonly=True,
),
}
136 changes: 86 additions & 50 deletions hr_expense_accountedge/hr_expense_accountedge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Odoo, Open Source Management Solution
# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -22,44 +22,48 @@
import time
import base64

from osv import orm, fields
from datetime import datetime
from openerp.osv import orm, fields
from openerp.tools.translate import _


class hr_expense_expense(orm.Model):
_inherit = 'hr.expense.expense'

def _create_csv_report(self, cr, uid, ids, context={}):
def _create_csv_report(self, cr, uid, ids, context=None):
res = {}
for id in ids:
this = self.browse(cr, uid, id)

output = this.employee_id.name
output += "\r\n"
output += "Employee\tCard ID\tDate\tVendor Invoice #\tAccount Number\tAmount\tDescription\
\tTax Code\tCurrency Code\tExchange Rate\r\n"
for expense in self.browse(cr, uid, ids, context=context):
output = (
expense.employee_id.name +
"\r\n"
"Employee\tCard ID\tDate\tVendor Invoice #\tAccount Number\t"
"Amount\tDescription\tTax Code\tCurrency Code\tExchange Rate"
"\r\n"
)
# Comment the previous line and uncomment the next one
# if you want to import taxes with their amount, instead of their code
# \tTax Code\tGST Amount\tPST/QST Amount\tCurrency Code\tExchange Rate\r\n"
# if you want to import taxes with their amount, instead of their
# code \tTax Code\tGST Amount\tPST/QST Amount\tCurrency Code\t
# Exchange Rate\r\n"

for l in this.line_ids:
for l in expense.line_ids:
taxes = self._compute_taxes(cr, uid, l, context)
# output += u"%s\t%s\t%s\t%s\t%s\t%.2f\t%s\t%s\t%.2f\t%.2f\t%s\t%.2f\r\n" % (
output += u"%s\t%s\t%s\t%s\t%s\t%.2f\t%s\t%s\t%s\t%.2f\r\n" % (
this.employee_id.name,
this.employee_id.supplier_id_accountedge,
expense.employee_id.name,
expense.employee_id.supplier_id_accountedge,
datetime.today().strftime("%d-%m-%Y"),
l.expense_id.id,
l.account_id.code,
taxes['amount_before_tax'],
l.name,
(l.tax_id.tax_code_accountedge or '000'),
# Comment the previous line and uncomment the next two ones
# if you want to import taxes with their amount, instead of their code
# if you want to import taxes with their amount, instead of
# their code
# taxes['amount_gst'],
# taxes['amount_pst'],
(l.expense_id.currency_id.name or 'CAD'),
(float(l.expense_id.currency_id.rate) or '1.0'))
(float(l.expense_id.currency_id.rate) or '1.0')
)

byte_string = output.encode('utf-8-sig')
res[id] = base64.encodestring(byte_string)
Expand All @@ -69,12 +73,14 @@ def _create_csv_report(self, cr, uid, ids, context={}):

return True

def _compute_taxes(self, cr, uid, expense_line, context={}):
def _compute_taxes(self, cr, uid, expense_line, context=None):
if context is None:
context = self.pool['res.users'].context_get(cr, uid)

res = {
'amount_before_tax': expense_line.total_amount,
'amount_gst': 0.0, # Goods and Services Tax, federal
'amount_pst': 0.0 # Provincial Sales Tax
'amount_gst': 0.0, # Goods and Services Tax, federal
'amount_pst': 0.0, # Provincial Sales Tax
}

tax = expense_line.tax_id
Expand All @@ -87,19 +93,25 @@ def _compute_taxes(self, cr, uid, expense_line, context={}):
tax_factor = 0.5

if tax.child_ids:
for child_tax in tax.child_ids: # TODO: the detection of the two taxes should be more reliable
# TODO: the detection of the two taxes should be more reliable
for child_tax in tax.child_ids:
if 'TPS' in child_tax.name or 'GST' in child_tax.name:
res['amount_gst'] = float(child_tax.amount) * tax_factor
else:
res['amount_pst'] = float(child_tax.amount) * tax_factor
else:
res['amount_gst'] = float(tax.amount)
res['amount_before_tax'] = expense_line.total_amount / (1 + res['amount_gst'] + res['amount_pst'])
res['amount_before_tax'] = (
expense_line.total_amount /
(1 + res['amount_gst'] + res['amount_pst'])
)
res['amount_gst'] = res['amount_before_tax'] * res['amount_gst']
res['amount_pst'] = res['amount_before_tax'] * res['amount_pst']
return res

def _add_attachment(self, cr, uid, ids, content, context={}):
def _add_attachment(self, cr, uid, ids, content, context=None):
if context is None:
context = self.pool['res.users'].context_get(cr, uid)

file_name = 'export_'+time.strftime('%Y%m%d_%H%M%S')+'.tsv'
self.pool.get('ir.attachment').create(cr, uid, {
Expand All @@ -123,8 +135,9 @@ def action_exported(self, cr, uid, ids, *args):
this = self.browse(cr, uid, id)
if not this.employee_id.supplier_id_accountedge:
raise orm.except_orm(
'Accountedge Supplier ID missing',
'Please add the Accountedge supplier ID on the employee before exporting the sheet.'
_('Accountedge Supplier ID missing'),
_('Please add the Accountedge supplier ID on the '
'employee before exporting the sheet.')
)
self._create_csv_report(cr, uid, ids, {})
self.write(cr, uid, ids, {'state': 'exported'})
Expand All @@ -139,24 +152,32 @@ def action_imported(self, cr, uid, ids, *args):

def _get_cur_account_manager(self, cr, uid, ids, field_name, arg, context):
res = {}
users_pool = self.pool['res.users']
employee_pool = self.pool['hr.employee']
for id in ids:
emails = ''
grp_ids = self.pool.get('res.groups').search(
cr, uid, [
('name', '=', u'Manager'),
('category_id.name', '=', u'Accounting & Finance')
]
], context=context
)
usr_ids = users_pool.search(
cr, uid, [('groups_id', '=', grp_ids[0])], context=context
)
usr_ids = self.pool.get('res.users').search(cr, uid, [('groups_id', '=', grp_ids[0])])
usrs = self.pool.get('res.users').browse(cr, uid, usr_ids)
usrs = users_pool.browse(cr, uid, usr_ids, context=context)

for user in usrs:
if user.user_email:
emails += user.user_email
emails += ','
else:
empl_id = self.pool.get('hr.employee').search(cr, uid, [('login', '=', user.login)])[0]
empl = self.pool.get('hr.employee').browse(cr, uid, empl_id)
empl_id = employee_pool.search(
cr, uid, [('login', '=', user.login)], context=context
)[0]
empl = employee_pool.browse(
cr, uid, empl_id, context=context
)
if empl.work_email:
emails += empl.work_email
emails += ','
Expand All @@ -165,22 +186,31 @@ def _get_cur_account_manager(self, cr, uid, ids, field_name, arg, context):
return res

_columns = {
'manager': fields.function(_get_cur_account_manager, string='Manager', type='char', size=128, readonly=True),
'state': fields.selection([
('draft', 'New'),
('confirm', 'Waiting Approval'),
('accepted', 'Approved'),
('exported', 'Exported'),
('imported', 'Imported'),
('cancelled', 'Refused'), ],
'State', readonly=True,
help="When the expense request is created the state is 'Draft'.\n"
"It is confirmed by the user and request is sent to admin, the state is 'Waiting Confirmation'.\n"
"If the admin accepts it, the state is 'Accepted'.\n"
"If the admin refuses it, the state is 'Refused'.\n"
"If a csv file has been generated for the expense request, the state is 'Exported'.\n"
"If the expense request has been imported in AccountEdge, the state is 'Imported'."
'manager': fields.function(
_get_cur_account_manager, string='Manager', type='char',
size=128, readonly=True
),
'state': fields.selection(
[
('draft', 'New'),
('confirm', 'Waiting Approval'),
('accepted', 'Approved'),
('exported', 'Exported'),
('imported', 'Imported'),
('cancelled', 'Refused'),
],
'State',
readonly=True,
help="""\
When the expense request is created the state is 'Draft'.
It is confirmed by the user and request is sent to admin, the state is \
'Waiting Confirmation'.
If the admin accepts it, the state is 'Accepted'.
If the admin refuses it, the state is 'Refused'.
If a csv file has been generated for the expense request, the state is \
'Exported'.
If the expense request has been imported in AccountEdge, the state is \
'Imported'."""),
}


Expand All @@ -189,11 +219,17 @@ class hr_expense_line(orm.Model):

def _get_parent_state(self, cr, uid, ids, field_name, arg, context):
res = {}
for id in ids:
expense_line = self.pool.get('hr.expense.line').browse(cr, uid, id)
res[id] = expense_line.expense_id.state
line_pool = self.pool['hr.expense.line']
for expense_line in line_pool.browse(cr, uid, ids, context=context):
res[expense_line.id] = expense_line.expense_id.state
return res

_columns = {
'state': fields.function(_get_parent_state, string='Expense State', type='char', size=128, readonly=True),
'state': fields.function(
_get_parent_state,
string='Expense State',
type='char',
size=128,
readonly=True,
),
}
Loading

0 comments on commit 1f0403f

Please sign in to comment.