1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # POS Membership module for OpenERP, Manage membership payments from POS.
5 # Copyright (C) 2013 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
7 # This file is a part of POS Membership
9 # POS Membership is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # ReMembership is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ##############################################################################
23 from openerp
.osv
import osv
24 from openerp
.osv
import fields
26 class pos_order(osv
.osv
):
27 _inherit
= 'pos.order'
29 def _check_membership_product(self
, cr
, uid
, ids
, context
=None):
30 #TODO : check condition and return boolean accordingly
31 if not context
is None:
33 order_line_obj
= self
.pool
.get('pos.order.line')
34 data_order_line
= order_line_obj
.browse(cr
, uid
, ids
, context
=context
)
35 for data
in data_order_line
:
36 print("DEV: [pos_membership] [_check_membership_product] [order_line]: data=%s product=%s" % (str(data
.id), str(data
.product_id
))),
40 (_check_membership_product
, 'Error: Invalid Message', ['field_name']),
43 # XXX: copied from openerp/addons/point_of_sale/point_of_sale.py
44 def action_invoice(self
, cr
, uid
, ids
, context
=None):
45 print ("DEV: [pos_membership] [pos_order] [action_invoice]");
46 wf_service
= netsvc
.LocalService("workflow")
47 inv_ref
= self
.pool
.get('account.invoice')
48 inv_line_ref
= self
.pool
.get('account.invoice.line')
49 product_obj
= self
.pool
.get('product.product')
52 for order
in self
.pool
.get('pos.order').browse(cr
, uid
, ids
, context
=context
):
54 inv_ids
.append(order
.invoice_id
.id)
57 if not order
.partner_id
:
58 raise osv
.except_osv(_('Error!'), _('Please provide a partner for the sale.'))
60 acc
= order
.partner_id
.property_account_receivable
.id
61 # XXX: copied from openerp/addons/point_of_sale/point_of_sale.py to fix account.invoice.line creation
66 'journal_id': order
.sale_journal
.id or None,
67 'type': 'out_invoice',
68 'reference': order
.name
,
69 'partner_id': order
.partner_id
.id,
70 'comment': order
.note
or '',
71 'currency_id': order
.pricelist_id
.currency_id
.id, # considering partner's sale pricelist's currency
74 inv
.update(inv_ref
.onchange_partner_id(cr
, uid
, [], 'out_invoice', order
.partner_id
.id)['value'])
75 if not inv
.get('account_id', None):
76 inv
['account_id'] = acc
77 for line
in order
.lines
:
79 #'invoice_id': inv_id,
80 'product_id': line
.product_id
.id,
83 inv_name
= product_obj
.name_get(cr
, uid
, [line
.product_id
.id], context
=context
)[0][1]
84 inv_line
.update(inv_line_ref
.product_id_change(cr
, uid
, [],
86 line
.product_id
.uom_id
.id,
87 line
.qty
, partner_id
= order
.partner_id
.id,
88 fposition_id
=order
.partner_id
.property_account_position
.id)['value'])
89 if line
.product_id
.description_sale
:
90 inv_line
['note'] = line
.product_id
.description_sale
91 inv_line
['price_unit'] = line
.price_unit
92 inv_line
['discount'] = line
.discount
93 inv_line
['name'] = inv_name
94 inv_line
['invoice_line_tax_id'] = ('invoice_line_tax_id' in inv_line
)\
95 and [(6, 0, inv_line
['invoice_line_tax_id'])] or []
96 #inv_line_ref.create(cr, uid, inv_line, context=context)
97 inv
['invoice_line'].append((0, 0, inv_line
))
98 inv_id
= inv_ref
.create(cr
, uid
, inv
, context
=context
)
100 self
.write(cr
, uid
, [order
.id], {'invoice_id': inv_id
, 'state': 'invoiced'}, context
=context
)
101 inv_ids
.append(inv_id
)
102 inv_ref
.button_reset_taxes(cr
, uid
, [inv_id
], context
=context
)
103 wf_service
.trg_validate(uid
, 'pos.order', order
.id, 'invoice', cr
)
105 if not inv_ids
: return {}
107 mod_obj
= self
.pool
.get('ir.model.data')
108 res
= mod_obj
.get_object_reference(cr
, uid
, 'account', 'invoice_form')
109 res_id
= res
and res
[1] or False
111 'name': _('Customer Invoice'),
115 'res_model': 'account.invoice',
116 'context': "{'type':'out_invoice'}",
117 'type': 'ir.actions.act_window',
120 'res_id': inv_ids
and inv_ids
[0] or False,
125 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: