Added a refund purchase button in the pos session form. This action creates a stateme...
[burette/bikecoop.git] / bikecoop.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # Bikecoop module for OpenERP, Custom module for bike coop'
5 # Copyright (C) 2012-2014 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
6 #
7 # This file is a part of Bikecoop
8 #
9 # Bikecoop 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.
13 #
14 # Bikecoop 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.
18 #
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/>.
21 #
22 ##############################################################################
23
24 from openerp.osv import fields, osv
25 import openerp.addons.decimal_precision as dp
26 from openerp.tools.translate import _
27 from openerp.addons.point_of_sale.wizard.pos_box import PosBoxOut
28
29 from datetime import date
30
31
32 class Theme(osv.osv):
33 _name = 'bikecoop.partner.theme'
34 _description = 'Themes that could be related to a partner'
35
36 _columns = {
37 'code': fields.char('Code', size=8, help='Code of the occupation'),
38 'name': fields.char('Name', size=128, help='Name of the job or studies', required=True, translate=True),
39 'domain': fields.selection([('gender', 'Gender'), ('occupation', 'Occupation'), ('volunteer', 'Volunteer')], 'Domain', required=True, size=24),
40 'active': fields.boolean('Active', help='If check, this object is always available'),
41 }
42
43 _defaults = {
44 'active': lambda *a: 1,
45 }
46
47 Theme()
48
49
50 class Partner(osv.osv):
51 _inherit = 'res.partner'
52
53 _columns = {
54 'nationality_id': fields.many2one('res.country', 'Nationality', help='Partner\'s nationality if he is a person'),
55 'year': fields.integer('Year of birth', help='This partner year of birth'),
56 'occupation_id': fields.many2one('bikecoop.partner.theme', 'Occupation', help='Main occupation of this partner'),
57 'volunteer_ids': fields.many2many('bikecoop.partner.theme', 'res_partner_bikecoop_theme_rel', 'partner_id', 'theme_id', 'Want to be volunteer?', help='What kind of volunteer activities you want to do with us?'),
58 'gender_id': fields.many2one('bikecoop.partner.theme', 'Gender'),
59 }
60
61 def _check_year(self, cr, uid, ids, context=None):
62 obj = self.browse(cr, uid, ids[0], context=context)
63 if obj.year:
64 if obj.year < 1900 or obj.year > date.today().year:
65 return False
66 return True
67
68 _constraints = [
69 (_check_year, 'Error: this year is not valid.', ['year']),
70 ]
71 Partner()
72
73
74 class product_template(osv.osv):
75 _inherit = 'product.template'
76
77 _columns = {
78 'standard_price': fields.float('Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user,point_of_sale.group_pos_user"),
79 }
80
81 product_template()
82
83 # Inheriting journal in order to define a purchase account which will be used when refunding an employee from an open register
84 class account_journal(osv.osv):
85 _inherit = 'account.journal'
86 _columns = {
87 'purchase_account_id' : fields.many2one('account.account', 'Purchase Account', select=1),
88 }
89 account_journal()
90
91 class PurchaseBox(PosBoxOut):
92 # Copied from account/wizard/pos_box.py since there is no way to overload the account used to create the statement
93 def _run(self, cr, uid, ids, records, context=None):
94 for box in self.browse(cr, uid, ids, context=context):
95 for record in records:
96 if not record.journal_id:
97 raise osv.except_osv(_('Error!'),
98 _("Please check that the field 'Journal' is set on the Bank Statement"))
99
100 if not record.journal_id.purchase_account_id:
101 raise osv.except_osv(_('Error!'),
102 _("Please check that the field 'Purchase Account' is set on the payment method '%s'.") % (record.journal_id.name,))
103
104 self._create_bank_statement_line(cr, uid, box, record, context=context)
105
106 return {}
107
108 def _compute_values_for_statement_line(self, cr, uid, box, record, context=None):
109 values = super(PosBoxOut, self)._compute_values_for_statement_line(cr, uid, box, record, context=context)
110 values['account_id'] = record.journal_id.purchase_account_id.id
111 return values
112
113 PurchaseBox()
114
115
116 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: