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
1=== added directory 'hr_expense_line_supplier'
2=== added file 'hr_expense_line_supplier/__init__.py'
3--- hr_expense_line_supplier/__init__.py 1970-01-01 00:00:00 +0000
4+++ hr_expense_line_supplier/__init__.py 2010-12-10 23:44:42 +0000
5@@ -0,0 +1,22 @@
6+# -*- encoding: utf-8 -*-
7+##############################################################################
8+#
9+# OpenERP, Open Source Management Solution
10+# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU General Public License for more details.
21+#
22+# You should have received a copy of the GNU General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+import hr_expense_line_supplier
27+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
28
29=== added file 'hr_expense_line_supplier/__openerp__.py'
30--- hr_expense_line_supplier/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ hr_expense_line_supplier/__openerp__.py 2010-12-10 23:44:42 +0000
32@@ -0,0 +1,41 @@
33+# -*- encoding: utf-8 -*-
34+##############################################################################
35+#
36+# OpenERP, Open Source Management Solution
37+# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
38+#
39+# This program is free software: you can redistribute it and/or modify
40+# it under the terms of the GNU General Public License as
41+# published by the Free Software Foundation, either version 3 of the
42+# License, or (at your option) any later version.
43+#
44+# This program is distributed in the hope that it will be useful,
45+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+# GNU General Public License for more details.
48+#
49+# You should have received a copy of the GNU General Public License
50+# along with this program. If not, see <http://www.gnu.org/licenses/>.
51+#
52+##############################################################################
53+{
54+ "name" : "Supplier on expense line",
55+ "version" : "1.0",
56+ "author" : "Savoir-faire Linux",
57+ "website" : "http://www.savoirfairelinux.com",
58+ "category" : "Human Resources",
59+ "description": """
60+ This module adds a supplier field on the expense line and set the taxes of
61+ the employee invoice based on the fiscal position of the supplier.
62+ """,
63+ "depends" : ['hr_expense'],
64+ "init_xml" : [],
65+ "update_xml" : [
66+ 'hr_expense.xml',
67+ ],
68+ "demo_xml" : [],
69+ "installable" : True,
70+ "certificate" : ''
71+}
72+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
73+
74
75=== added file 'hr_expense_line_supplier/hr_expense.xml'
76--- hr_expense_line_supplier/hr_expense.xml 1970-01-01 00:00:00 +0000
77+++ hr_expense_line_supplier/hr_expense.xml 2010-12-10 23:44:42 +0000
78@@ -0,0 +1,27 @@
79+<openerp>
80+ <data>
81+
82+ <record id="view_expenses_form" model="ir.ui.view">
83+ <field name="name">hr.expense.form.inherit</field>
84+ <field name="model">hr.expense.expense</field>
85+ <field name="inherit_id" ref="hr_expense.view_expenses_form"/>
86+ <field name="arch" type="xml">
87+ <field name="product_id" position="after">
88+ <field name="partner_id" domain="[('supplier','=',True)]" select="2"/>
89+ </field>
90+ </field>
91+ </record>
92+
93+ <record id="view_expenses_tree" model="ir.ui.view">
94+ <field name="name">hr.expense.line.tree.inherit</field>
95+ <field name="model">hr.expense.line</field>
96+ <field name="inherit_id" ref="hr_expense.view_expenses_line_tree"/>
97+ <field name="arch" type="xml">
98+ <field name="analytic_account" position="after">
99+ <field name="partner_id"/>
100+ </field>
101+ </field>
102+ </record>
103+
104+ </data>
105+</openerp>
106
107=== added file 'hr_expense_line_supplier/hr_expense_line_supplier.py'
108--- hr_expense_line_supplier/hr_expense_line_supplier.py 1970-01-01 00:00:00 +0000
109+++ hr_expense_line_supplier/hr_expense_line_supplier.py 2010-12-10 23:44:42 +0000
110@@ -0,0 +1,117 @@
111+# -*- encoding: utf-8 -*-
112+##############################################################################
113+#
114+# OpenERP, Open Source Management Solution
115+# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
116+#
117+# This program is free software: you can redistribute it and/or modify
118+# it under the terms of the GNU General Public License as
119+# published by the Free Software Foundation, either version 3 of the
120+# License, or (at your option) any later version.
121+#
122+# This program is distributed in the hope that it will be useful,
123+# but WITHOUT ANY WARRANTY; without even the implied warranty of
124+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
125+# GNU General Public License for more details.
126+#
127+# You should have received a copy of the GNU General Public License
128+# along with this program. If not, see <http://www.gnu.org/licenses/>.
129+#
130+##############################################################################
131+
132+import netsvc
133+
134+from osv import osv, fields
135+
136+class hr_expense_line(osv.osv):
137+ _inherit = 'hr.expense.line'
138+ _columns = {
139+ 'partner_id': fields.many2one('res.partner', 'Supplier', required=True),
140+ }
141+
142+hr_expense_line()
143+
144+class hr_expense_expense(osv.osv):
145+ _inherit = 'hr.expense.expense'
146+
147+ def action_invoice_create(self, cr, uid, ids):
148+ res = False
149+ invoice_obj = self.pool.get('account.invoice')
150+ property_obj = self.pool.get('ir.property')
151+ sequence_obj = self.pool.get('ir.sequence')
152+ analytic_journal_obj = self.pool.get('account.analytic.journal')
153+ account_journal = self.pool.get('account.journal')
154+ for exp in self.browse(cr, uid, ids):
155+ lines = []
156+ for l in exp.line_ids:
157+ tax_id = []
158+ tax_tmp = []
159+ if l.product_id:
160+ acc = l.product_id.product_tmpl_id.property_account_expense
161+ if not acc:
162+ acc = l.product_id.categ_id.property_account_expense_categ
163+ tax_tmp = [x.id for x in l.product_id.supplier_taxes_id]
164+ for tx in range(0, len(l.partner_id.property_account_position.tax_ids)):
165+ 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]
166+ else:
167+ acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category')
168+ if not acc:
169+ raise osv.except_osv(_('Error !'), _('Please configure Default Expanse account for Product purchase, `property_account_expense_categ`'))
170+
171+ lines.append((0, False, {
172+ 'name': l.name,
173+ 'account_id': acc.id,
174+ 'price_unit': l.unit_amount,
175+ 'quantity': l.unit_quantity,
176+ 'uos_id': l.uom_id.id,
177+ 'product_id': l.product_id and l.product_id.id or False,
178+ 'invoice_line_tax_id': tax_id and [(6, 0, tax_id)] or False,
179+ 'account_analytic_id': l.analytic_account.id,
180+ }))
181+ if not exp.employee_id.address_home_id:
182+ raise osv.except_osv(_('Error !'), _('The employee must have a home address'))
183+ acc = exp.employee_id.address_home_id.partner_id.property_account_payable.id
184+ payment_term_id = exp.employee_id.address_home_id.partner_id.property_payment_term.id
185+ inv = {
186+ 'name': exp.name,
187+ 'reference': sequence_obj.get(cr, uid, 'hr.expense.invoice'),
188+ 'account_id': acc,
189+ 'type': 'in_invoice',
190+ 'partner_id': exp.employee_id.address_home_id.partner_id.id,
191+ 'address_invoice_id': exp.employee_id.address_home_id.id,
192+ 'address_contact_id': exp.employee_id.address_home_id.id,
193+ 'origin': exp.name,
194+ 'invoice_line': lines,
195+ 'currency_id': exp.currency_id.id,
196+ 'payment_term': payment_term_id,
197+ 'fiscal_position': exp.employee_id.address_home_id.partner_id.property_account_position.id
198+ }
199+ if payment_term_id:
200+ to_update = invoice_obj.onchange_payment_term_date_invoice(cr, uid, [], payment_term_id, None)
201+ if to_update:
202+ inv.update(to_update['value'])
203+ journal = False
204+ if exp.journal_id:
205+ inv['journal_id']=exp.journal_id.id
206+ journal = exp.journal_id
207+ else:
208+ journal_id = invoice_obj._get_journal(cr, uid, context={'type': 'in_invoice'})
209+ if journal_id:
210+ inv['journal_id'] = journal_id
211+ journal = account_journal.browse(cr, uid, journal_id)
212+ if journal and not journal.analytic_journal_id:
213+ analytic_journal_ids = analytic_journal_obj.search(cr, uid, [('type','=','purchase')])
214+ if analytic_journal_ids:
215+ account_journal.write(cr, uid, [journal.id],{'analytic_journal_id':analytic_journal_ids[0]})
216+ inv_id = invoice_obj.create(cr, uid, inv, {'type': 'in_invoice'})
217+ invoice_obj.button_compute(cr, uid, [inv_id], {'type': 'in_invoice'}, set_total=True)
218+ wf_service = netsvc.LocalService("workflow")
219+ wf_service.trg_validate(uid, 'account.invoice', inv_id, 'invoice_open', cr)
220+
221+ self.write(cr, uid, [exp.id], {'invoice_id': inv_id, 'state': 'invoiced'})
222+ res = inv_id
223+ return res
224+
225+hr_expense_expense()
226+
227+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
228
229=== added directory 'hr_expense_line_supplier/i18n'

Subscribers

People subscribed via source and target branches