Merge lp:~openerp-canada/openobject-addons/hr_expense_line_supplier into lp:openobject-addons/extra-trunk

Status: Merged
Merge reported by: Maxime Chambreuil (http://www.savoirfairelinux.com)
Merged at revision: not available
Proposed branch: lp:~openerp-canada/openobject-addons/hr_expense_line_supplier
Merge into: lp:openobject-addons/extra-trunk
Diff against target: 229 lines (+207/-0)
4 files modified
hr_expense_line_supplier/__init__.py (+22/-0)
hr_expense_line_supplier/__openerp__.py (+41/-0)
hr_expense_line_supplier/hr_expense.xml (+27/-0)
hr_expense_line_supplier/hr_expense_line_supplier.py (+117/-0)
To merge this branch: bzr merge lp:~openerp-canada/openobject-addons/hr_expense_line_supplier
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+40593@code.launchpad.net

Description of the change

Add supplier field to expense line

To post a comment you must log in.
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'hr_expense_line_supplier'
=== added file 'hr_expense_line_supplier/__init__.py'
--- hr_expense_line_supplier/__init__.py 1970-01-01 00:00:00 +0000
+++ hr_expense_line_supplier/__init__.py 2010-12-10 23:44:42 +0000
@@ -0,0 +1,22 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21import hr_expense_line_supplier
22# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
023
=== added file 'hr_expense_line_supplier/__openerp__.py'
--- hr_expense_line_supplier/__openerp__.py 1970-01-01 00:00:00 +0000
+++ hr_expense_line_supplier/__openerp__.py 2010-12-10 23:44:42 +0000
@@ -0,0 +1,41 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 "name" : "Supplier on expense line",
23 "version" : "1.0",
24 "author" : "Savoir-faire Linux",
25 "website" : "http://www.savoirfairelinux.com",
26 "category" : "Human Resources",
27 "description": """
28 This module adds a supplier field on the expense line and set the taxes of
29 the employee invoice based on the fiscal position of the supplier.
30 """,
31 "depends" : ['hr_expense'],
32 "init_xml" : [],
33 "update_xml" : [
34 'hr_expense.xml',
35 ],
36 "demo_xml" : [],
37 "installable" : True,
38 "certificate" : ''
39}
40# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
41
042
=== added file 'hr_expense_line_supplier/hr_expense.xml'
--- hr_expense_line_supplier/hr_expense.xml 1970-01-01 00:00:00 +0000
+++ hr_expense_line_supplier/hr_expense.xml 2010-12-10 23:44:42 +0000
@@ -0,0 +1,27 @@
1<openerp>
2 <data>
3
4 <record id="view_expenses_form" model="ir.ui.view">
5 <field name="name">hr.expense.form.inherit</field>
6 <field name="model">hr.expense.expense</field>
7 <field name="inherit_id" ref="hr_expense.view_expenses_form"/>
8 <field name="arch" type="xml">
9 <field name="product_id" position="after">
10 <field name="partner_id" domain="[('supplier','=',True)]" select="2"/>
11 </field>
12 </field>
13 </record>
14
15 <record id="view_expenses_tree" model="ir.ui.view">
16 <field name="name">hr.expense.line.tree.inherit</field>
17 <field name="model">hr.expense.line</field>
18 <field name="inherit_id" ref="hr_expense.view_expenses_line_tree"/>
19 <field name="arch" type="xml">
20 <field name="analytic_account" position="after">
21 <field name="partner_id"/>
22 </field>
23 </field>
24 </record>
25
26 </data>
27</openerp>
028
=== added file 'hr_expense_line_supplier/hr_expense_line_supplier.py'
--- hr_expense_line_supplier/hr_expense_line_supplier.py 1970-01-01 00:00:00 +0000
+++ hr_expense_line_supplier/hr_expense_line_supplier.py 2010-12-10 23:44:42 +0000
@@ -0,0 +1,117 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22import netsvc
23
24from osv import osv, fields
25
26class hr_expense_line(osv.osv):
27 _inherit = 'hr.expense.line'
28 _columns = {
29 'partner_id': fields.many2one('res.partner', 'Supplier', required=True),
30 }
31
32hr_expense_line()
33
34class hr_expense_expense(osv.osv):
35 _inherit = 'hr.expense.expense'
36
37 def action_invoice_create(self, cr, uid, ids):
38 res = False
39 invoice_obj = self.pool.get('account.invoice')
40 property_obj = self.pool.get('ir.property')
41 sequence_obj = self.pool.get('ir.sequence')
42 analytic_journal_obj = self.pool.get('account.analytic.journal')
43 account_journal = self.pool.get('account.journal')
44 for exp in self.browse(cr, uid, ids):
45 lines = []
46 for l in exp.line_ids:
47 tax_id = []
48 tax_tmp = []
49 if l.product_id:
50 acc = l.product_id.product_tmpl_id.property_account_expense
51 if not acc:
52 acc = l.product_id.categ_id.property_account_expense_categ
53 tax_tmp = [x.id for x in l.product_id.supplier_taxes_id]
54 for tx in range(0, len(l.partner_id.property_account_position.tax_ids)):
55 tax_id = [(y if y != l.partner_id.property_account_position.tax_ids[tx].tax_src_id.id else l.partner_id.property_account_position.tax_ids[tx].tax_dest_id.id) for y in tax_tmp]
56 else:
57 acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category')
58 if not acc:
59 raise osv.except_osv(_('Error !'), _('Please configure Default Expanse account for Product purchase, `property_account_expense_categ`'))
60
61 lines.append((0, False, {
62 'name': l.name,
63 'account_id': acc.id,
64 'price_unit': l.unit_amount,
65 'quantity': l.unit_quantity,
66 'uos_id': l.uom_id.id,
67 'product_id': l.product_id and l.product_id.id or False,
68 'invoice_line_tax_id': tax_id and [(6, 0, tax_id)] or False,
69 'account_analytic_id': l.analytic_account.id,
70 }))
71 if not exp.employee_id.address_home_id:
72 raise osv.except_osv(_('Error !'), _('The employee must have a home address'))
73 acc = exp.employee_id.address_home_id.partner_id.property_account_payable.id
74 payment_term_id = exp.employee_id.address_home_id.partner_id.property_payment_term.id
75 inv = {
76 'name': exp.name,
77 'reference': sequence_obj.get(cr, uid, 'hr.expense.invoice'),
78 'account_id': acc,
79 'type': 'in_invoice',
80 'partner_id': exp.employee_id.address_home_id.partner_id.id,
81 'address_invoice_id': exp.employee_id.address_home_id.id,
82 'address_contact_id': exp.employee_id.address_home_id.id,
83 'origin': exp.name,
84 'invoice_line': lines,
85 'currency_id': exp.currency_id.id,
86 'payment_term': payment_term_id,
87 'fiscal_position': exp.employee_id.address_home_id.partner_id.property_account_position.id
88 }
89 if payment_term_id:
90 to_update = invoice_obj.onchange_payment_term_date_invoice(cr, uid, [], payment_term_id, None)
91 if to_update:
92 inv.update(to_update['value'])
93 journal = False
94 if exp.journal_id:
95 inv['journal_id']=exp.journal_id.id
96 journal = exp.journal_id
97 else:
98 journal_id = invoice_obj._get_journal(cr, uid, context={'type': 'in_invoice'})
99 if journal_id:
100 inv['journal_id'] = journal_id
101 journal = account_journal.browse(cr, uid, journal_id)
102 if journal and not journal.analytic_journal_id:
103 analytic_journal_ids = analytic_journal_obj.search(cr, uid, [('type','=','purchase')])
104 if analytic_journal_ids:
105 account_journal.write(cr, uid, [journal.id],{'analytic_journal_id':analytic_journal_ids[0]})
106 inv_id = invoice_obj.create(cr, uid, inv, {'type': 'in_invoice'})
107 invoice_obj.button_compute(cr, uid, [inv_id], {'type': 'in_invoice'}, set_total=True)
108 wf_service = netsvc.LocalService("workflow")
109 wf_service.trg_validate(uid, 'account.invoice', inv_id, 'invoice_open', cr)
110
111 self.write(cr, uid, [exp.id], {'invoice_id': inv_id, 'state': 'invoiced'})
112 res = inv_id
113 return res
114
115hr_expense_expense()
116
117# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
0118
=== added directory 'hr_expense_line_supplier/i18n'

Subscribers

People subscribed via source and target branches