From 0c9c22e539d9621a3e6ac1673a81a0176893bb56 Mon Sep 17 00:00:00 2001 From: Hardik Date: Mon, 9 Jul 2012 17:11:52 +0530 Subject: [PATCH 001/173] [FIX] project :KeyError: 'company_id' when group by 'Company' lp bug: https://launchpad.net/bugs/1022496 fixed bzr revid: hsa@tinyerp.com-20120709114152-s9mv0m67b2r5v63r --- addons/project/report/project_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/project/report/project_report.py b/addons/project/report/project_report.py index 36e025ab509..1d74e154c37 100644 --- a/addons/project/report/project_report.py +++ b/addons/project/report/project_report.py @@ -52,7 +52,7 @@ class report_project_task_user(osv.osv): ('0','Very urgent')], 'Priority', readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), 'state': fields.selection([('draft', 'Draft'), ('open', 'In Progress'), ('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')],'Status', readonly=True), - 'company_id': fields.many2one('res.company', 'Company', readonly=True, groups="base.group_multi_company"), + 'company_id': fields.many2one('res.company', 'Company', readonly=True), 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True), } _order = 'name desc, project_id' From 1a2d054b8499a78f6f4f8a2024c3b561502a93e5 Mon Sep 17 00:00:00 2001 From: Jose Patricio Villarreal <> Date: Wed, 11 Jul 2012 16:59:15 +0530 Subject: [PATCH 002/173] [FIX] added warning message in bank statement line,raise when invoice is already canceled lp bug: https://launchpad.net/bugs/1022677 fixed bzr revid: rmu@tinyerp.com-20120711112915-ffl9q3nn721hppjt --- addons/account_voucher/account_voucher.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 2cefaf15f0e..dc46ec57722 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -1047,6 +1047,8 @@ class account_voucher(osv.osv): # if the amount encoded in voucher is equal to the amount unreconciled, we need to compute the # currency rate difference if line.amount == line.amount_unreconciled: + if not line.move_line_id.amount_residual: + raise osv.except_osv(_('Wrong bank statement line'),_("You must have delete the bank statement line manualy to which the payment was reconcile. Please check the payment of the partner %s by the amount of %s !")%(line.voucher_id.partner_id.name, line.voucher_id.amount)) currency_rate_difference = line.move_line_id.amount_residual - amount else: currency_rate_difference = 0.0 From 70028097b9683696d9b26e5782df71b0414eeae3 Mon Sep 17 00:00:00 2001 From: "Ravish Murari (OpenERP)" Date: Mon, 16 Jul 2012 18:40:00 +0530 Subject: [PATCH 003/173] [FIX] recurring models for account not showing company lp bug: https://launchpad.net/bugs/999315 fixed bzr revid: rmu@tinyerp.com-20120716131000-tvwhhz4xcmwpubaj --- addons/account/account_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 80202d97d6c..9fd37ea94fe 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1547,7 +1547,7 @@ - + @@ -1567,7 +1567,7 @@ - + From d397e599f546329ed659c4355f893e9a240fbee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Wed, 22 Aug 2012 15:55:46 +0200 Subject: [PATCH 004/173] [BRANCH] locadis: first commit : start of the branch bzr revid: fva@openerp.com-20120822135546-kwbo893th1pv2vbs --- addons/locadis/__init__.py | 25 + addons/locadis/__openerp__.py | 56 ++ addons/locadis/point_of_sale.py | 1303 +++++++++++++++++++++++++ addons/locadis/static/src/css/pos.css | 4 + addons/locadis/static/src/js/hello.js | 12 + addons/locadis/static/src/js/main.js | 24 + addons/locadis/static/src/xml/pos.xml | 15 + 7 files changed, 1439 insertions(+) create mode 100644 addons/locadis/__init__.py create mode 100644 addons/locadis/__openerp__.py create mode 100644 addons/locadis/point_of_sale.py create mode 100644 addons/locadis/static/src/css/pos.css create mode 100644 addons/locadis/static/src/js/hello.js create mode 100644 addons/locadis/static/src/js/main.js create mode 100644 addons/locadis/static/src/xml/pos.xml diff --git a/addons/locadis/__init__.py b/addons/locadis/__init__.py new file mode 100644 index 00000000000..e57b362135b --- /dev/null +++ b/addons/locadis/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +#import point_of_sale + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/locadis/__openerp__.py b/addons/locadis/__openerp__.py new file mode 100644 index 00000000000..056b8da7fcf --- /dev/null +++ b/addons/locadis/__openerp__.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Locadis Point Of Sale', + 'version': '1.0.1', + 'category': 'Point Of Sale', + "sequence": 6, + "summary": "Point of sale extensions for Locadis", + 'description': """ +FIXME: product description + """, + 'author': 'OpenERP SA', + 'images': ['images/cash_registers.jpeg', 'images/pos_analysis.jpeg','images/register_analysis.jpeg','images/sale_order_pos.jpeg','images/product_pos.jpeg'], + 'depends': ['point_of_sale'], + 'init_xml': [], + 'update_xml': [ + ], + 'demo_xml': [ + ], + 'test': [ + ], + 'installable': True, + 'application': True, + # Web client + 'js': [ + 'static/src/js/main.js' + ], + 'css': [ + 'static/src/css/pos.css' + ], + 'qweb': [ + 'static/src/xml/pos.xml' + ], + 'auto_install': False, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/locadis/point_of_sale.py b/addons/locadis/point_of_sale.py new file mode 100644 index 00000000000..f4d32985688 --- /dev/null +++ b/addons/locadis/point_of_sale.py @@ -0,0 +1,1303 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import pdb +import openerp +import addons +import openerp.addons.product.product + +import time +from datetime import datetime +from dateutil.relativedelta import relativedelta +import logging + +import netsvc +from osv import fields, osv +import tools +from tools.translate import _ +from decimal import Decimal +import decimal_precision as dp + +_logger = logging.getLogger(__name__) + +class pos_config(osv.osv): + _name = 'pos.config' + + POS_CONFIG_STATE = [ + ('active', 'Active'), + ('inactive', 'Inactive'), + ('deprecated', 'Deprecated') + ] + + _columns = { + 'name' : fields.char('Point of Sale Name', size=32, select=1, + required=True, help="An internal identification of the point of sale"), + 'journal_ids' : fields.many2many('account.journal', 'pos_config_journal_rel', + 'pos_config_id', 'journal_id', 'Available Payment Methods', + domain="[('journal_user', '=', True )]",), + 'shop_id' : fields.many2one('sale.shop', 'Shop', + required=True), + 'journal_id' : fields.many2one('account.journal', 'Sale Journal', + domain=[('type', '=', 'sale')], + help="Accounting journal used to post sales entries."), + 'iface_self_checkout' : fields.boolean('Self Checkout Mode', + help="Check this if this point of sale should open by default in a self checkout mode. If unchecked, OpenERP uses the normal cashier mode by default."), + 'iface_cashdrawer' : fields.boolean('Cashdrawer Interface'), + 'iface_payment_terminal' : fields.boolean('Payment Terminal Interface'), + 'iface_electronic_scale' : fields.boolean('Electronic Scale Interface'), + 'iface_vkeyboard' : fields.boolean('Virtual KeyBoard Interface'), + 'iface_print_via_proxy' : fields.boolean('Print via Proxy'), + + 'state' : fields.selection(POS_CONFIG_STATE, 'State', required=True, readonly=True), + 'sequence_id' : fields.many2one('ir.sequence', 'Order IDs Sequence', readonly=True, + help="This sequence is automatically created by OpenERP but you can change it "\ + "to customize the reference numbers of your orders."), + 'session_ids': fields.one2many('pos.session', 'config_id', 'Sessions'), + 'group_by' : fields.boolean('Group Journal Items', help="Check this if you want to group the Journal Items by Product while closing a Session"), + } + + def name_get(self, cr, uid, ids, context=None): + result = [] + states = { + 'opening_control': _('Opening Control'), + 'opened': _('In Progress'), + 'closing_control': _('Closing Control'), + 'closed': _('Closed & Posted'), + } + for record in self.browse(cr, uid, ids, context=context): + if (not record.session_ids) or (record.session_ids[0].state=='closed'): + result.append((record.id, record.name+' ('+_('not used')+')')) + continue + session = record.session_ids[0] + result.append((record.id, record.name + ' ('+session.user_id.name+')')) #, '+states[session.state]+')')) + return result + + + def _default_payment_journal(self, cr, uid, context=None): + res = self.pool.get('account.journal').search(cr, uid, [('type', 'in', ('bank','cash'))], limit=2) + return res or [] + + def _default_sale_journal(self, cr, uid, context=None): + res = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'sale')], limit=1) + return res and res[0] or False + + def _default_shop(self, cr, uid, context=None): + res = self.pool.get('sale.shop').search(cr, uid, []) + return res and res[0] or False + + _defaults = { + 'state' : POS_CONFIG_STATE[0][0], + 'shop_id': _default_shop, + 'journal_id': _default_sale_journal, + 'journal_ids': _default_payment_journal, + 'group_by' : True, + } + + def set_active(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'state' : 'active'}, context=context) + + def set_inactive(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'state' : 'inactive'}, context=context) + + def set_deprecate(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'state' : 'deprecated'}, context=context) + + def create(self, cr, uid, values, context=None): + proxy = self.pool.get('ir.sequence') + sequence_values = dict( + name='PoS %s' % values['name'], + padding=5, + prefix="%s/" % values['name'], + ) + sequence_id = proxy.create(cr, uid, sequence_values, context=context) + values['sequence_id'] = sequence_id + return super(pos_config, self).create(cr, uid, values, context=context) + + def unlink(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + if obj.sequence_id: + obj.sequence_id.unlink() + return super(pos_config, self).unlink(cr, uid, ids, context=context) + +class pos_session(osv.osv): + _name = 'pos.session' + _order = 'id desc' + + POS_SESSION_STATE = [ + ('opening_control', 'Opening Control'), # Signal open + ('opened', 'In Progress'), # Signal closing + ('closing_control', 'Closing Control'), # Signal close + ('closed', 'Closed & Posted'), + ] + + def _compute_cash_journal_id(self, cr, uid, ids, fieldnames, args, context=None): + result = dict.fromkeys(ids, False) + for record in self.browse(cr, uid, ids, context=context): + for st in record.statement_ids: + if st.journal_id.type == 'cash': + result[record.id] = st.journal_id.id + break + return result + + def _compute_cash_register_id(self, cr, uid, ids, fieldnames, args, context=None): + result = dict.fromkeys(ids, False) + for record in self.browse(cr, uid, ids, context=context): + for st in record.statement_ids: + if st.journal_id.type == 'cash': + result[record.id] = st.id + break + return result + + def _compute_controls(self, cr, uid, ids, fieldnames, args, context=None): + result = {} + + for record in self.browse(cr, uid, ids, context=context): + has_opening_control = False + has_closing_control = False + + for journal in record.config_id.journal_ids: + if journal.opening_control == True: + has_opening_control = True + if journal.closing_control == True: + has_closing_control = True + + if has_opening_control and has_closing_control: + break + + values = { + 'has_opening_control': has_opening_control, + 'has_closing_control': has_closing_control, + } + result[record.id] = values + + return result + + _columns = { + 'config_id' : fields.many2one('pos.config', 'Point of Sale', + help="The physical point of sale you will use.", + required=True, + select=1, + domain="[('state', '=', 'active')]", + ), + + 'name' : fields.char('Session ID', size=32, required=True, readonly=True), + 'user_id' : fields.many2one('res.users', 'Responsible', + required=True, + select=1, + readonly=True, + states={'opening_control' : [('readonly', False)]} + ), + 'start_at' : fields.datetime('Opening Date', readonly=True), + 'stop_at' : fields.datetime('Closing Date', readonly=True), + + 'state' : fields.selection(POS_SESSION_STATE, 'State', + required=True, readonly=True, + select=1), + + 'cash_journal_id' : fields.function(_compute_cash_journal_id, method=True, + type='many2one', relation='account.journal', + string='Cash Journal', store=True), + 'cash_register_id' : fields.function(_compute_cash_register_id, method=True, + type='many2one', relation='account.bank.statement', + string='Cash Register', store=True), + + 'opening_details_ids' : fields.related('cash_register_id', 'opening_details_ids', + type='one2many', relation='account.cashbox.line', + string='Opening Cash Control'), + 'details_ids' : fields.related('cash_register_id', 'details_ids', + type='one2many', relation='account.cashbox.line', + string='Cash Control'), + + 'cash_register_balance_end_real' : fields.related('cash_register_id', 'balance_end_real', + type='float', + digits_compute=dp.get_precision('Account'), + string="Ending Balance", + help="Computed using the cash control lines", + readonly=True), + 'cash_register_balance_start' : fields.related('cash_register_id', 'balance_start', + type='float', + digits_compute=dp.get_precision('Account'), + string="Starting Balance", + help="Computed using the cash control at the opening.", + readonly=True), + 'cash_register_total_entry_encoding' : fields.related('cash_register_id', 'total_entry_encoding', + string='Total Cash Transaction', + readonly=True), + 'cash_register_balance_end' : fields.related('cash_register_id', 'balance_end', + type='float', + digits_compute=dp.get_precision('Account'), + string="Computed Balance", + help="Computed with the initial cash control and the sum of all payments.", + readonly=True), + 'cash_register_difference' : fields.related('cash_register_id', 'difference', + type='float', + string='Difference', + help="Difference between the counted cash control at the closing and the computed balance.", + readonly=True), + + 'journal_ids' : fields.related('config_id', 'journal_ids', + type='many2many', + readonly=True, + relation='account.journal', + string='Available Payment Methods'), + 'order_ids' : fields.one2many('pos.order', 'session_id', 'Orders'), + + 'statement_ids' : fields.one2many('account.bank.statement', 'pos_session_id', 'Bank Statement', readonly=True), + 'has_opening_control' : fields.function(_compute_controls, string='Has Opening Control', multi='control', type='boolean'), + 'has_closing_control' : fields.function(_compute_controls, string='Has Closing Control', multi='control', type='boolean'), + } + + _defaults = { + 'name' : '/', + 'user_id' : lambda obj, cr, uid, context: uid, + 'state' : 'opening_control', + } + + _sql_constraints = [ + ('uniq_name', 'unique(name)', "The name of this POS Session must be unique !"), + ] + + def _check_unicity(self, cr, uid, ids, context=None): + for session in self.browse(cr, uid, ids, context=None): + # open if there is no session in 'opening_control', 'opened', 'closing_control' for one user + domain = [ + ('state', 'not in', ('closed','closing_control')), + ('user_id', '=', uid) + ] + count = self.search_count(cr, uid, domain, context=context) + if count>1: + return False + return True + + def _check_pos_config(self, cr, uid, ids, context=None): + for session in self.browse(cr, uid, ids, context=None): + domain = [ + ('state', '!=', 'closed'), + ('config_id', '=', session.config_id.id) + ] + count = self.search_count(cr, uid, domain, context=context) + if count>1: + return False + return True + + _constraints = [ + (_check_unicity, "You cannot create two active sessions with the same responsible!", ['user_id', 'state']), + (_check_pos_config, "You cannot create two active sessions related to the same point of sale!", ['config_id']), + ] + + def create(self, cr, uid, values, context=None): + config_id = values.get('config_id', False) or False + if config_id: + # journal_id is not required on the pos_config because it does not + # exists at the installation. If nothing is configured at the + # installation we do the minimal configuration. Impossible to do in + # the .xml files as the CoA is not yet installed. + jobj = self.pool.get('pos.config') + pos_config = jobj.browse(cr, uid, config_id, context=context) + if not pos_config.journal_id: + jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] + if jid: + jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context) + else: + raise osv.except_osv( _('error!'), + _("Unable to open the session. You have to assign a sale journal to your point of sale.")) + + # define some cash journal if no payment method exists + if not pos_config.journal_ids: + cashids = self.pool.get('account.journal').search(cr, uid, [('journal_user','=',True)], context=context) + if not cashids: + cashids = self.pool.get('account.journal').search(cr, uid, [('type','=','cash')], context=context) + self.pool.get('account.journal').write(cr, uid, cashids, {'journal_user': True}) + jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) + + + pos_config = jobj.browse(cr, uid, config_id, context=context) + bank_statement_ids = [] + for journal in pos_config.journal_ids: + bank_values = { + 'journal_id' : journal.id, + 'user_id' : uid, + } + statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) + bank_statement_ids.append(statement_id) + + values.update({ + 'name' : pos_config.sequence_id._next(), + 'statement_ids' : [(6, 0, bank_statement_ids)], + 'config_id': config_id + }) + + return super(pos_session, self).create(cr, uid, values, context=context) + + def unlink(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + for statement in obj.statement_ids: + statement.unlink(context=context) + return True + + def wkf_action_open(self, cr, uid, ids, context=None): + # second browse because we need to refetch the data from the DB for cash_register_id + for record in self.browse(cr, uid, ids, context=context): + values = {} + if not record.start_at: + values['start_at'] = time.strftime('%Y-%m-%d %H:%M:%S') + values['state'] = 'opened' + record.write(values, context=context) + for st in record.statement_ids: + st.button_open(context=context) + + return self.open_frontend_cb(cr, uid, ids, context=context) + + def wkf_action_opening_control(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'state' : 'opening_control'}, context=context) + + def wkf_action_closing_control(self, cr, uid, ids, context=None): + for session in self.browse(cr, uid, ids, context=context): + for statement in session.statement_ids: + if statement.id <> session.cash_register_id.id: + if statement.balance_end<>statement.balance_end_real: + self.pool.get('account.bank.statement').write(cr, uid, + [statement.id], {'balance_end_real': statement.balance_end}) + return self.write(cr, uid, ids, {'state' : 'closing_control', 'stop_at' : time.strftime('%Y-%m-%d %H:%M:%S')}, context=context) + + def wkf_action_close(self, cr, uid, ids, context=None): + # Close CashBox + bsl = self.pool.get('account.bank.statement.line') + for record in self.browse(cr, uid, ids, context=context): + for st in record.statement_ids: + if abs(st.difference) > st.journal_id.amount_authorized_diff: + # The pos manager can close statements with maximums. + if not self.pool.get('ir.model.access').check_groups(cr, uid, "point_of_sale.group_pos_manager"): + raise osv.except_osv( _('Error!'), + _("Your ending balance is too different from the theorical cash closing (%.2f), the maximum allowed is: %.2f. You can contact your manager to force it.") % (st.difference, st.journal_id.amount_authorized_diff)) + if st.difference: + if st.difference > 0.0: + name= _('Point of Sale Profit') + account_id = st.journal_id.profit_account_id.id + else: + account_id = st.journal_id.loss_account_id.id + name= _('Point of Sale Loss') + if not account_id: + raise osv.except_osv( _('Error!'), + _("Please set your profit and loss accounts on your payment method '%s'. This will allow OpenERP to post the difference of %.2f in your ending balance. To close this session, you can update the 'Closing Cash Control' to avoid any difference.") % (st.journal_id.name,st.difference)) + bsl.create(cr, uid, { + 'statement_id': st.id, + 'amount': st.difference, + 'ref': record.name, + 'name': name, + 'account_id': account_id + }, context=context) + + getattr(st, 'button_confirm_%s' % st.journal_id.type)(context=context) + self._confirm_orders(cr, uid, ids, context=context) + self.write(cr, uid, ids, {'state' : 'closed'}, context=context) + + obj = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'point_of_sale', 'menu_point_root')[1] + return { + 'type' : 'ir.actions.client', + 'name' : 'Point of Sale Menu', + 'tag' : 'reload', + 'params' : {'menu_id': obj}, + } + + def _confirm_orders(self, cr, uid, ids, context=None): + wf_service = netsvc.LocalService("workflow") + + for session in self.browse(cr, uid, ids, context=context): + order_ids = [order.id for order in session.order_ids if order.state == 'paid'] + + move_id = self.pool.get('account.move').create(cr, uid, {'ref' : session.name, 'journal_id' : session.config_id.journal_id.id, }, context=context) + + self.pool.get('pos.order')._create_account_move_line(cr, uid, order_ids, session, move_id, context=context) + + for order in session.order_ids: + if order.state != 'paid': + raise osv.except_osv( + _('Error!'), + _("You cannot confirm all orders of this session, because they have not the 'paid' status")) + else: + wf_service.trg_validate(uid, 'pos.order', order.id, 'done', cr) + + return True + + def open_frontend_cb(self, cr, uid, ids, context=None): + if not context: + context = {} + if not ids: + return {} + context.update({'session_id' : ids[0]}) + return { + 'type' : 'ir.actions.client', + 'name' : 'Start Point Of Sale', + 'tag' : 'pos.ui', + 'context' : context, + } + +class pos_order(osv.osv): + _name = "pos.order" + _description = "Point of Sale" + _order = "id desc" + + def create_from_ui(self, cr, uid, orders, context=None): + #_logger.info("orders: %r", orders) + order_ids = [] + for tmp_order in orders: + order = tmp_order['data'] + order_id = self.create(cr, uid, { + 'name': order['name'], + 'user_id': order['user_id'] or False, + 'session_id': order['pos_session_id'], + 'lines': order['lines'] + }, context) + + for payments in order['statement_ids']: + payment = payments[2] + self.add_payment(cr, uid, order_id, { + 'amount': payment['amount'] or 0.0, + 'payment_date': payment['name'], + 'payment_name': payment.get('note', False), + 'journal': payment['journal_id'] + }, context=context) + + if order['amount_return']: + session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context) + self.add_payment(cr, uid, order_id, { + 'amount': -order['amount_return'], + 'payment_date': time.strftime('%Y-%m-%d %H:%M:%S'), + 'payment_name': _('return'), + 'journal': session.cash_journal_id.id + }, context=context) + order_ids.append(order_id) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'pos.order', order_id, 'paid', cr) + return order_ids + + def unlink(self, cr, uid, ids, context=None): + for rec in self.browse(cr, uid, ids, context=context): + if rec.state not in ('draft','cancel'): + raise osv.except_osv(_('Unable to Delete !'), _('In order to delete a sale, it must be new or cancelled.')) + return super(pos_order, self).unlink(cr, uid, ids, context=context) + + def onchange_partner_id(self, cr, uid, ids, part=False, context=None): + if not part: + return {'value': {}} + pricelist = self.pool.get('res.partner').browse(cr, uid, part, context=context).property_product_pricelist.id + return {'value': {'pricelist_id': pricelist}} + + def _amount_all(self, cr, uid, ids, name, args, context=None): + tax_obj = self.pool.get('account.tax') + cur_obj = self.pool.get('res.currency') + res = {} + for order in self.browse(cr, uid, ids, context=context): + res[order.id] = { + 'amount_paid': 0.0, + 'amount_return':0.0, + 'amount_tax':0.0, + } + val1 = val2 = 0.0 + cur = order.pricelist_id.currency_id + for payment in order.statement_ids: + res[order.id]['amount_paid'] += payment.amount + res[order.id]['amount_return'] += (payment.amount < 0 and payment.amount or 0) + for line in order.lines: + val1 += line.price_subtotal_incl + val2 += line.price_subtotal + res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val1-val2) + res[order.id]['amount_total'] = cur_obj.round(cr, uid, cur, val1) + return res + + def copy(self, cr, uid, id, default=None, context=None): + if not default: + default = {} + d = { + 'state': 'draft', + 'invoice_id': False, + 'account_move': False, + 'picking_id': False, + 'statement_ids': [], + 'nb_print': 0, + 'name': self.pool.get('ir.sequence').get(cr, uid, 'pos.order'), + } + d.update(default) + return super(pos_order, self).copy(cr, uid, id, d, context=context) + + _columns = { + 'name': fields.char('Order Ref', size=64, required=True, readonly=True), + 'company_id':fields.many2one('res.company', 'Company', required=True, readonly=True), + 'shop_id': fields.related('session_id', 'config_id', 'shop_id', relation='sale.shop', type='many2one', string='Shop', store=True, readonly=True), + 'date_order': fields.datetime('Order Date', readonly=True, select=True), + 'user_id': fields.many2one('res.users', 'Salesman', help="Person who uses the the cash register. It can be a reliever, a student or an interim employee."), + 'amount_tax': fields.function(_amount_all, string='Taxes', digits_compute=dp.get_precision('Point Of Sale'), multi='all'), + 'amount_total': fields.function(_amount_all, string='Total', multi='all'), + 'amount_paid': fields.function(_amount_all, string='Paid', states={'draft': [('readonly', False)]}, readonly=True, digits_compute=dp.get_precision('Point Of Sale'), multi='all'), + 'amount_return': fields.function(_amount_all, 'Returned', digits_compute=dp.get_precision('Point Of Sale'), multi='all'), + 'lines': fields.one2many('pos.order.line', 'order_id', 'Order Lines', states={'draft': [('readonly', False)]}, readonly=True), + 'statement_ids': fields.one2many('account.bank.statement.line', 'pos_statement_id', 'Payments', states={'draft': [('readonly', False)]}, readonly=True), + 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, states={'draft': [('readonly', False)]}, readonly=True), + 'partner_id': fields.many2one('res.partner', 'Customer', change_default=True, select=1, states={'draft': [('readonly', False)], 'paid': [('readonly', False)]}), + + 'session_id' : fields.many2one('pos.session', 'Session', + #required=True, + select=1, + domain="[('state', '=', 'opened')]", + states={'draft' : [('readonly', False)]}, + readonly=True), + + 'state': fields.selection([('draft', 'New'), + ('cancel', 'Cancelled'), + ('paid', 'Paid'), + ('done', 'Posted'), + ('invoiced', 'Invoiced')], + 'Status', readonly=True), + + 'invoice_id': fields.many2one('account.invoice', 'Invoice'), + 'account_move': fields.many2one('account.move', 'Journal Entry', readonly=True), + 'picking_id': fields.many2one('stock.picking', 'Picking', readonly=True), + 'note': fields.text('Internal Notes'), + 'nb_print': fields.integer('Number of Print', readonly=True), + + 'sale_journal': fields.related('session_id', 'config_id', 'journal_id', relation='account.journal', type='many2one', string='Sale Journal', store=True, readonly=True), + } + + def _default_session(self, cr, uid, context=None): + so = self.pool.get('pos.session') + session_ids = so.search(cr, uid, [('state','=', 'opened'), ('user_id','=',uid)], context=context) + return session_ids and session_ids[0] or False + + def _default_pricelist(self, cr, uid, context=None): + res = self.pool.get('sale.shop').search(cr, uid, [], context=context) + if res: + shop = self.pool.get('sale.shop').browse(cr, uid, res[0], context=context) + return shop.pricelist_id and shop.pricelist_id.id or False + return False + + _defaults = { + 'user_id': lambda self, cr, uid, context: uid, + 'state': 'draft', + 'name': '/', + 'date_order': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), + 'nb_print': 0, + 'session_id': _default_session, + 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, + 'pricelist_id': _default_pricelist, + } + + def create(self, cr, uid, values, context=None): + values['name'] = self.pool.get('ir.sequence').get(cr, uid, 'pos.order') + return super(pos_order, self).create(cr, uid, values, context=context) + + def test_paid(self, cr, uid, ids, context=None): + """A Point of Sale is paid when the sum + @return: True + """ + for order in self.browse(cr, uid, ids, context=context): + if order.lines and not order.amount_total: + return True + if (not order.lines) or (not order.statement_ids) or \ + (abs(order.amount_total-order.amount_paid) > 0.00001): + return False + return True + + def create_picking(self, cr, uid, ids, context=None): + """Create a picking for each order and validate it.""" + picking_obj = self.pool.get('stock.picking') + partner_obj = self.pool.get('res.partner') + move_obj = self.pool.get('stock.move') + + for order in self.browse(cr, uid, ids, context=context): + if not order.state=='draft': + continue + addr = order.partner_id and partner_obj.address_get(cr, uid, [order.partner_id.id], ['delivery']) or {} + picking_id = picking_obj.create(cr, uid, { + 'origin': order.name, + 'partner_id': addr.get('delivery',False), + 'type': 'out', + 'company_id': order.company_id.id, + 'move_type': 'direct', + 'note': order.note or "", + 'invoice_state': 'none', + 'auto_picking': True, + }, context=context) + self.write(cr, uid, [order.id], {'picking_id': picking_id}, context=context) + location_id = order.shop_id.warehouse_id.lot_stock_id.id + output_id = order.shop_id.warehouse_id.lot_output_id.id + + for line in order.lines: + if line.product_id and line.product_id.type == 'service': + continue + if line.qty < 0: + location_id, output_id = output_id, location_id + + move_obj.create(cr, uid, { + 'name': line.name, + 'product_uom': line.product_id.uom_id.id, + 'product_uos': line.product_id.uom_id.id, + 'picking_id': picking_id, + 'product_id': line.product_id.id, + 'product_uos_qty': abs(line.qty), + 'product_qty': abs(line.qty), + 'tracking_id': False, + 'state': 'draft', + 'location_id': location_id, + 'location_dest_id': output_id, + }, context=context) + if line.qty < 0: + location_id, output_id = output_id, location_id + + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) + picking_obj.force_assign(cr, uid, [picking_id], context) + return True + + def cancel_order(self, cr, uid, ids, context=None): + """ Changes order state to cancel + @return: True + """ + stock_picking_obj = self.pool.get('stock.picking') + for order in self.browse(cr, uid, ids, context=context): + wf_service.trg_validate(uid, 'stock.picking', order.picking_id.id, 'button_cancel', cr) + if stock_picking_obj.browse(cr, uid, order.picking_id.id, context=context).state <> 'cancel': + raise osv.except_osv(_('Error!'), _('Unable to cancel the picking.')) + self.write(cr, uid, ids, {'state': 'cancel'}, context=context) + return True + + def add_payment(self, cr, uid, order_id, data, context=None): + """Create a new payment for the order""" + if not context: + context = {} + statement_obj = self.pool.get('account.bank.statement') + statement_line_obj = self.pool.get('account.bank.statement.line') + prod_obj = self.pool.get('product.product') + property_obj = self.pool.get('ir.property') + curr_c = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id + curr_company = curr_c.id + order = self.browse(cr, uid, order_id, context=context) + args = { + 'amount': data['amount'], + } + if 'payment_date' in data: + args['date'] = data['payment_date'] + args['name'] = order.name + if data.get('payment_name', False): + args['name'] = args['name'] + ': ' + data['payment_name'] + account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context) + args['account_id'] = (order.partner_id and order.partner_id.property_account_receivable \ + and order.partner_id.property_account_receivable.id) or (account_def and account_def.id) or False + args['partner_id'] = order.partner_id and order.partner_id.id or None + + if not args['account_id']: + if not args['partner_id']: + msg = _('There is no receivable account defined to make payment.') + else: + msg = _('There is no receivable account defined to make payment for the partner: "%s" (id:%d).') % (order.partner_id.name, order.partner_id.id,) + raise osv.except_osv(_('Configuration Error!'), msg) + + context.pop('pos_session_id', False) + + try: + journal_id = long(data['journal']) + except Exception: + journal_id = False + + statement_id = False + for statement in order.session_id.statement_ids: + if statement.journal_id.id == journal_id: + statement_id = statement.id + break + + if not statement_id: + raise osv.except_osv(_('Error!'), _('You have to open at least one cashbox.')) + + args.update({ + 'statement_id' : statement_id, + 'pos_statement_id' : order_id, + 'journal_id' : journal_id, + 'type' : 'customer', + 'ref' : order.name, + }) + + statement_line_obj.create(cr, uid, args, context=context) + + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'pos.order', order_id, 'paid', cr) + wf_service.trg_write(uid, 'pos.order', order_id, cr) + + return statement_id + + def refund(self, cr, uid, ids, context=None): + """Create a copy of order for refund order""" + clone_list = [] + line_obj = self.pool.get('pos.order.line') + for order in self.browse(cr, uid, ids, context=context): + clone_id = self.copy(cr, uid, order.id, { + 'name': order.name + ' REFUND', + }, context=context) + clone_list.append(clone_id) + + for clone in self.browse(cr, uid, clone_list, context=context): + for order_line in clone.lines: + line_obj.write(cr, uid, [order_line.id], { + 'qty': -order_line.qty + }, context=context) + + new_order = ','.join(map(str,clone_list)) + abs = { + #'domain': "[('id', 'in', ["+new_order+"])]", + 'name': _('Return Products'), + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'pos.order', + 'res_id':clone_list[0], + 'view_id': False, + 'context':context, + 'type': 'ir.actions.act_window', + 'nodestroy': True, + 'target': 'current', + } + return abs + + def action_invoice_state(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'state':'invoiced'}, context=context) + + def action_invoice(self, cr, uid, ids, context=None): + wf_service = netsvc.LocalService("workflow") + inv_ref = self.pool.get('account.invoice') + inv_line_ref = self.pool.get('account.invoice.line') + product_obj = self.pool.get('product.product') + inv_ids = [] + + for order in self.pool.get('pos.order').browse(cr, uid, ids, context=context): + if order.invoice_id: + inv_ids.append(order.invoice_id.id) + continue + + if not order.partner_id: + raise osv.except_osv(_('Error!'), _('Please provide a partner for the sale.')) + + acc = order.partner_id.property_account_receivable.id + inv = { + 'name': order.name, + 'origin': order.name, + 'account_id': acc, + 'journal_id': order.sale_journal.id or None, + 'type': 'out_invoice', + 'reference': order.name, + 'partner_id': order.partner_id.id, + 'comment': order.note or '', + 'currency_id': order.pricelist_id.currency_id.id, # considering partner's sale pricelist's currency + } + inv.update(inv_ref.onchange_partner_id(cr, uid, [], 'out_invoice', order.partner_id.id)['value']) + if not inv.get('account_id', None): + inv['account_id'] = acc + inv_id = inv_ref.create(cr, uid, inv, context=context) + + self.write(cr, uid, [order.id], {'invoice_id': inv_id, 'state': 'invoiced'}, context=context) + inv_ids.append(inv_id) + for line in order.lines: + inv_line = { + 'invoice_id': inv_id, + 'product_id': line.product_id.id, + 'quantity': line.qty, + } + inv_name = product_obj.name_get(cr, uid, [line.product_id.id], context=context)[0][1] + inv_line.update(inv_line_ref.product_id_change(cr, uid, [], + line.product_id.id, + line.product_id.uom_id.id, + line.qty, partner_id = order.partner_id.id, + fposition_id=order.partner_id.property_account_position.id)['value']) + if line.product_id.description_sale: + inv_line['note'] = line.product_id.description_sale + inv_line['price_unit'] = line.price_unit + inv_line['discount'] = line.discount + inv_line['name'] = inv_name + inv_line['invoice_line_tax_id'] = ('invoice_line_tax_id' in inv_line)\ + and [(6, 0, inv_line['invoice_line_tax_id'])] or [] + inv_line_ref.create(cr, uid, inv_line, context=context) + inv_ref.button_reset_taxes(cr, uid, [inv_id], context=context) + wf_service.trg_validate(uid, 'pos.order', order.id, 'invoice', cr) + + if not inv_ids: return {} + + mod_obj = self.pool.get('ir.model.data') + res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form') + res_id = res and res[1] or False + return { + 'name': _('Customer Invoice'), + 'view_type': 'form', + 'view_mode': 'form', + 'view_id': [res_id], + 'res_model': 'account.invoice', + 'context': "{'type':'out_invoice'}", + 'type': 'ir.actions.act_window', + 'nodestroy': True, + 'target': 'current', + 'res_id': inv_ids and inv_ids[0] or False, + } + + def create_account_move(self, cr, uid, ids, context=None): + return self._create_account_move_line(cr, uid, ids, None, None, context=context) + + def _create_account_move_line(self, cr, uid, ids, session=None, move_id=None, context=None): + # Tricky, via the workflow, we only have one id in the ids variable + """Create a account move line of order grouped by products or not.""" + account_move_obj = self.pool.get('account.move') + account_move_line_obj = self.pool.get('account.move.line') + account_period_obj = self.pool.get('account.period') + account_tax_obj = self.pool.get('account.tax') + user_proxy = self.pool.get('res.users') + property_obj = self.pool.get('ir.property') + + period = account_period_obj.find(cr, uid, context=context)[0] + + #session_ids = set(order.session_id for order in self.browse(cr, uid, ids, context=context)) + + if session and not all(session.id == order.session_id.id for order in self.browse(cr, uid, ids, context=context)): + raise osv.except_osv(_('Error!'), _('Selected orders do not have the same session!')) + + current_company = user_proxy.browse(cr, uid, uid, context=context).company_id + + grouped_data = {} + have_to_group_by = session and session.config_id.group_by or False + + def compute_tax(amount, tax, line): + if amount > 0: + tax_code_id = tax['base_code_id'] + tax_amount = line.price_subtotal * tax['base_sign'] + else: + tax_code_id = tax['ref_base_code_id'] + tax_amount = line.price_subtotal * tax['ref_base_sign'] + + return (tax_code_id, tax_amount,) + + for order in self.browse(cr, uid, ids, context=context): + if order.account_move: + continue + if order.state != 'paid': + continue + + user_company = user_proxy.browse(cr, order.user_id.id, order.user_id.id).company_id + + group_tax = {} + account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context).id + + order_account = order.partner_id and \ + order.partner_id.property_account_receivable and \ + order.partner_id.property_account_receivable.id or account_def or current_company.account_receivable.id + + if move_id is None: + # Create an entry for the sale + move_id = account_move_obj.create(cr, uid, { + 'ref' : order.name, + 'journal_id': order.sale_journal.id, + }, context=context) + + def insert_data(data_type, values): + # if have_to_group_by: + + sale_journal_id = order.sale_journal.id + + # 'quantity': line.qty, + # 'product_id': line.product_id.id, + values.update({ + 'date': order.date_order[:10], + 'ref': order.name, + 'journal_id' : sale_journal_id, + 'period_id' : period, + 'move_id' : move_id, + 'company_id': user_company and user_company.id or False, + }) + + if data_type == 'product': + key = ('product', values['product_id'],) + elif data_type == 'tax': + key = ('tax', values['tax_code_id'],) + elif data_type == 'counter_part': + key = ('counter_part', values['partner_id'], values['account_id']) + else: + return + + grouped_data.setdefault(key, []) + + # if not have_to_group_by or (not grouped_data[key]): + # grouped_data[key].append(values) + # else: + # pass + + if have_to_group_by: + if not grouped_data[key]: + grouped_data[key].append(values) + else: + current_value = grouped_data[key][0] + current_value['quantity'] = current_value.get('quantity', 0.0) + values.get('quantity', 0.0) + current_value['credit'] = current_value.get('credit', 0.0) + values.get('credit', 0.0) + current_value['debit'] = current_value.get('debit', 0.0) + values.get('debit', 0.0) + current_value['tax_amount'] = current_value.get('tax_amount', 0.0) + values.get('tax_amount', 0.0) + else: + grouped_data[key].append(values) + + # Create an move for each order line + + for line in order.lines: + tax_amount = 0 + taxes = [t for t in line.product_id.taxes_id] + computed_taxes = account_tax_obj.compute_all(cr, uid, taxes, line.price_unit * (100.0-line.discount) / 100.0, line.qty)['taxes'] + + for tax in computed_taxes: + tax_amount += round(tax['amount'], 2) + group_key = (tax['tax_code_id'], tax['base_code_id'], tax['account_collected_id'], tax['id']) + + group_tax.setdefault(group_key, 0) + group_tax[group_key] += round(tax['amount'], 2) + + amount = line.price_subtotal + + # Search for the income account + if line.product_id.property_account_income.id: + income_account = line.product_id.property_account_income.id + elif line.product_id.categ_id.property_account_income_categ.id: + income_account = line.product_id.categ_id.property_account_income_categ.id + else: + raise osv.except_osv(_('Error!'), _('Please define income '\ + 'account for this product: "%s" (id:%d).') \ + % (line.product_id.name, line.product_id.id, )) + + # Empty the tax list as long as there is no tax code: + tax_code_id = False + tax_amount = 0 + while computed_taxes: + tax = computed_taxes.pop(0) + tax_code_id, tax_amount = compute_tax(amount, tax, line) + + # If there is one we stop + if tax_code_id: + break + + # Create a move for the line + insert_data('product', { + 'name': line.product_id.name, + 'quantity': line.qty, + 'product_id': line.product_id.id, + 'account_id': income_account, + 'credit': ((amount>0) and amount) or 0.0, + 'debit': ((amount<0) and -amount) or 0.0, + 'tax_code_id': tax_code_id, + 'tax_amount': tax_amount, + 'partner_id': order.partner_id and order.partner_id.id or False + }) + + # For each remaining tax with a code, whe create a move line + for tax in computed_taxes: + tax_code_id, tax_amount = compute_tax(amount, tax, line) + if not tax_code_id: + continue + + insert_data('tax', { + 'name': _('Tax'), + 'product_id':line.product_id.id, + 'quantity': line.qty, + 'account_id': income_account, + 'credit': 0.0, + 'debit': 0.0, + 'tax_code_id': tax_code_id, + 'tax_amount': tax_amount, + }) + + # Create a move for each tax group + (tax_code_pos, base_code_pos, account_pos, tax_id)= (0, 1, 2, 3) + + for key, tax_amount in group_tax.items(): + tax = self.pool.get('account.tax').browse(cr, uid, key[tax_id], context=context) + insert_data('tax', { + 'name': _('Tax') + ' ' + tax.name, + 'quantity': line.qty, + 'product_id': line.product_id.id, + 'account_id': key[account_pos], + 'credit': ((tax_amount>0) and tax_amount) or 0.0, + 'debit': ((tax_amount<0) and -tax_amount) or 0.0, + 'tax_code_id': key[tax_code_pos], + 'tax_amount': tax_amount, + }) + + # counterpart + insert_data('counter_part', { + 'name': _("Trade Receivables"), #order.name, + 'account_id': order_account, + 'credit': ((order.amount_total < 0) and -order.amount_total) or 0.0, + 'debit': ((order.amount_total > 0) and order.amount_total) or 0.0, + 'partner_id': order.partner_id and order.partner_id.id or False + }) + + order.write({'state':'done', 'account_move': move_id}) + + for group_key, group_data in grouped_data.iteritems(): + for value in group_data: + account_move_line_obj.create(cr, uid, value, context=context) + + return True + + def action_payment(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'state': 'payment'}, context=context) + + def action_paid(self, cr, uid, ids, context=None): + self.create_picking(cr, uid, ids, context=context) + self.write(cr, uid, ids, {'state': 'paid'}, context=context) + return True + + def action_cancel(self, cr, uid, ids, context=None): + self.write(cr, uid, ids, {'state': 'cancel'}, context=context) + return True + + def action_done(self, cr, uid, ids, context=None): + self.create_account_move(cr, uid, ids, context=context) + return True + +class account_bank_statement(osv.osv): + _inherit = 'account.bank.statement' + _columns= { + 'user_id': fields.many2one('res.users', 'User', readonly=True), + } + _defaults = { + 'user_id': lambda self,cr,uid,c={}: uid + } +account_bank_statement() + +class account_bank_statement_line(osv.osv): + _inherit = 'account.bank.statement.line' + _columns= { + 'pos_statement_id': fields.many2one('pos.order', ondelete='cascade'), + } +account_bank_statement_line() + +class pos_order_line(osv.osv): + _name = "pos.order.line" + _description = "Lines of Point of Sale" + _rec_name = "product_id" + + def _amount_line_all(self, cr, uid, ids, field_names, arg, context=None): + res = dict([(i, {}) for i in ids]) + account_tax_obj = self.pool.get('account.tax') + cur_obj = self.pool.get('res.currency') + for line in self.browse(cr, uid, ids, context=context): + taxes = line.product_id.taxes_id + price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + taxes = account_tax_obj.compute_all(cr, uid, line.product_id.taxes_id, price, line.qty, product=line.product_id, partner=line.order_id.partner_id or False) + + cur = line.order_id.pricelist_id.currency_id + res[line.id]['price_subtotal'] = cur_obj.round(cr, uid, cur, taxes['total']) + res[line.id]['price_subtotal_incl'] = cur_obj.round(cr, uid, cur, taxes['total_included']) + return res + + def onchange_product_id(self, cr, uid, ids, pricelist, product_id, qty=0, partner_id=False, context=None): + context = context or {} + if not product_id: + return {} + if not pricelist: + raise osv.except_osv(_('No Pricelist !'), + _('You have to select a pricelist in the sale form !\n' \ + 'Please set one before choosing a product.')) + + price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist], + product_id, qty or 1.0, partner_id)[pricelist] + + result = self.onchange_qty(cr, uid, ids, product_id, 0.0, qty, price, context=context) + result['value']['price_unit'] = price + return result + + def onchange_qty(self, cr, uid, ids, product, discount, qty, price_unit, context=None): + result = {} + if not product: + return result + account_tax_obj = self.pool.get('account.tax') + cur_obj = self.pool.get('res.currency') + + prod = self.pool.get('product.product').browse(cr, uid, product, context=context) + + taxes = prod.taxes_id + price = price_unit * (1 - (discount or 0.0) / 100.0) + taxes = account_tax_obj.compute_all(cr, uid, prod.taxes_id, price, qty, product=prod, partner=False) + + result['price_subtotal'] = taxes['total'] + result['price_subtotal_incl'] = taxes['total_included'] + return {'value': result} + + _columns = { + 'company_id': fields.many2one('res.company', 'Company', required=True), + 'name': fields.char('Line No', size=32, required=True), + 'notice': fields.char('Discount Notice', size=128), + 'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], required=True, change_default=True), + 'price_unit': fields.float(string='Unit Price', digits=(16, 2)), + 'qty': fields.float('Quantity', digits=(16, 2)), + 'price_subtotal': fields.function(_amount_line_all, multi='pos_order_line_amount', string='Subtotal w/o Tax', store=True), + 'price_subtotal_incl': fields.function(_amount_line_all, multi='pos_order_line_amount', string='Subtotal', store=True), + 'discount': fields.float('Discount (%)', digits=(16, 2)), + 'order_id': fields.many2one('pos.order', 'Order Ref', ondelete='cascade'), + 'create_date': fields.datetime('Creation Date', readonly=True), + } + + _defaults = { + 'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'pos.order.line'), + 'qty': lambda *a: 1, + 'discount': lambda *a: 0.0, + 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, + } + + def copy_data(self, cr, uid, id, default=None, context=None): + if not default: + default = {} + default.update({ + 'name': self.pool.get('ir.sequence').get(cr, uid, 'pos.order.line') + }) + return super(pos_order_line, self).copy_data(cr, uid, id, default, context=context) + +class pos_category(osv.osv): + _name = 'pos.category' + _description = "Point of Sale Category" + _order = "sequence, name" + def _check_recursion(self, cr, uid, ids, context=None): + level = 100 + while len(ids): + cr.execute('select distinct parent_id from pos_category where id IN %s',(tuple(ids),)) + ids = filter(None, map(lambda x:x[0], cr.fetchall())) + if not level: + return False + level -= 1 + return True + + _constraints = [ + (_check_recursion, 'Error ! You cannot create recursive categories.', ['parent_id']) + ] + + def name_get(self, cr, uid, ids, context=None): + if not len(ids): + return [] + reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) + res = [] + for record in reads: + name = record['name'] + if record['parent_id']: + name = record['parent_id'][1]+' / '+name + res.append((record['id'], name)) + return res + + def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): + res = self.name_get(cr, uid, ids, context=context) + return dict(res) + + def _get_image(self, cr, uid, ids, name, args, context=None): + result = dict.fromkeys(ids, False) + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = tools.image_get_resized_images(obj.image) + return result + + def _set_image(self, cr, uid, id, name, value, args, context=None): + return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) + + _columns = { + 'name': fields.char('Name', size=64, required=True, translate=True), + 'complete_name': fields.function(_name_get_fnc, type="char", string='Name'), + 'parent_id': fields.many2one('pos.category','Parent Category', select=True), + 'child_id': fields.one2many('pos.category', 'parent_id', string='Children Categories'), + 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."), + + # NOTE: there is no 'default image', because by default we don't show thumbnails for categories. However if we have a thumbnail + # for at least one category, then we display a default image on the other, so that the buttons have consistent styling. + # In this case, the default image is set by the js code. + + 'image': fields.binary("Image", + help="This field holds the image used for the category. "\ + "The image is base64 encoded, and PIL-supported. "\ + "It is limited to a 1024x1024 px image."), + 'image_medium': fields.function(_get_image, fnct_inv=_set_image, + string="Medium-sized image", type="binary", multi="_get_image", + store = { + 'pos.category': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized image of the category. It is automatically "\ + "resized as a 180x180 px image, with aspect ratio preserved. "\ + "Use this field in form views or some kanban views."), + 'image_small': fields.function(_get_image, fnct_inv=_set_image, + string="Smal-sized image", type="binary", multi="_get_image", + store = { + 'pos.category': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized image of the category. It is automatically "\ + "resized as a 50x50 px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required."), + } + +import io, StringIO + +class ean_wizard(osv.osv_memory): + _name = 'pos.ean_wizard' + _columns = { + 'ean13_pattern': fields.char('Ean13 Pattern', size=32, required=True, translate=True), + } + def sanitize_ean13(self, cr, uid, ids, context): + for r in self.browse(cr,uid,ids): + ean13 = openerp.addons.product.product.sanitize_ean13(r.ean13_pattern) + m = context.get('active_model') + m_id = context.get('active_id') + self.pool.get(m).write(cr,uid,[m_id],{'ean13':ean13}) + return { 'type' : 'ir.actions.act_window_close' } + +class product_product(osv.osv): + _inherit = 'product.product' + + + #def _get_small_image(self, cr, uid, ids, prop, unknow_none, context=None): + # result = {} + # for obj in self.browse(cr, uid, ids, context=context): + # if not obj.product_image: + # result[obj.id] = False + # continue + + # image_stream = io.BytesIO(obj.product_image.decode('base64')) + # img = Image.open(image_stream) + # img.thumbnail((120, 100), Image.ANTIALIAS) + # img_stream = StringIO.StringIO() + # img.save(img_stream, "JPEG") + # result[obj.id] = img_stream.getvalue().encode('base64') + # return result + + _columns = { + 'income_pdt': fields.boolean('Point of Sale Cash In', help="This is a product you can use to put cash into a statement for the point of sale backend."), + 'expense_pdt': fields.boolean('Point of Sale Cash Out', help="This is a product you can use to take cash from a statement for the point of sale backend, exemple: money lost, transfer to bank, etc."), + 'pos_categ_id': fields.many2one('pos.category','Point of Sale Category', + help="If you want to sell this product through the point of sale, select the category it belongs to."), + 'to_weight' : fields.boolean('To Weight', help="This category contains products that should be weighted, mainly used for the self-checkout interface"), + } + _defaults = { + 'to_weight' : False, + } + + def edit_ean(self, cr, uid, ids, context): + return { + 'name': "Edit Ean", + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'pos.ean_wizard', + 'target' : 'new', + 'view_id': False, + 'context':context, + } + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/locadis/static/src/css/pos.css b/addons/locadis/static/src/css/pos.css new file mode 100644 index 00000000000..d9ec3ba7cee --- /dev/null +++ b/addons/locadis/static/src/css/pos.css @@ -0,0 +1,4 @@ + +.product-list-empty{ + text-align:center; +} diff --git a/addons/locadis/static/src/js/hello.js b/addons/locadis/static/src/js/hello.js new file mode 100644 index 00000000000..7deacfa994c --- /dev/null +++ b/addons/locadis/static/src/js/hello.js @@ -0,0 +1,12 @@ + +openerp.locadis = function(instance){ + console.log('Hello World!:',instance); + instance.point_of_sale.PosWidget = instance.point_of_sale.PosWidget.extend({ + init:function(parent,options){ + console.log('Tadaaam!',parent,options); + this._super(parent,options); + }, + }); + + /* REMOVE PRODUCTS FROM FIRST LEVEL IN SELF CHECKOUT */ +}; diff --git a/addons/locadis/static/src/js/main.js b/addons/locadis/static/src/js/main.js new file mode 100644 index 00000000000..1d0f41d8360 --- /dev/null +++ b/addons/locadis/static/src/js/main.js @@ -0,0 +1,24 @@ +openerp.locadis = function(instance){ + + var module = instance.point_of_sale; + var QWeb = instance.web.qweb; + + module.ProductListWidget = module.ProductListWidget.extend({ + template_empty: 'ProductEmptyListWidget', + get_category: function(){ + return this.getParent().product_categories_widget.category; + }, + renderElement: function(){ + var ss = this.pos_widget.screen_selector; + console.log('ss',ss); + if(this.get_category().name === 'Root' && ss && ss.get_user_mode() === 'cashier'){ + this.replaceElement(_.str.trim(QWeb.render(this.template_empty,{widget:this}))); + }else{ + this._super(); + } + }, + }); +}; + + + diff --git a/addons/locadis/static/src/xml/pos.xml b/addons/locadis/static/src/xml/pos.xml new file mode 100644 index 00000000000..f69c3b788df --- /dev/null +++ b/addons/locadis/static/src/xml/pos.xml @@ -0,0 +1,15 @@ + + + + +
+
+

Please scan an item

+ +
+
+
+
+ + +
From 0d70cdaaf51993a13acbf6964d34e71e601b0525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Thu, 23 Aug 2012 14:18:35 +0200 Subject: [PATCH 005/173] [IMP] locadis: dont_vidange and extra fields added to products bzr revid: fva@openerp.com-20120823121835-o3119dcmu9s0048t --- addons/locadis/__init__.py | 2 +- addons/locadis/__openerp__.py | 10 +++------- addons/locadis/static/src/css/pos.css | 4 +++- addons/locadis/static/src/xml/pos.xml | 3 +-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/addons/locadis/__init__.py b/addons/locadis/__init__.py index e57b362135b..60ffcac8393 100644 --- a/addons/locadis/__init__.py +++ b/addons/locadis/__init__.py @@ -19,7 +19,7 @@ # ############################################################################## -#import point_of_sale +import locadis # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/locadis/__openerp__.py b/addons/locadis/__openerp__.py index 056b8da7fcf..4ec8527fc7a 100644 --- a/addons/locadis/__openerp__.py +++ b/addons/locadis/__openerp__.py @@ -30,14 +30,10 @@ FIXME: product description """, 'author': 'OpenERP SA', - 'images': ['images/cash_registers.jpeg', 'images/pos_analysis.jpeg','images/register_analysis.jpeg','images/sale_order_pos.jpeg','images/product_pos.jpeg'], + 'images': [], 'depends': ['point_of_sale'], - 'init_xml': [], - 'update_xml': [ - ], - 'demo_xml': [ - ], - 'test': [ + 'data':[ + 'locadis_views.xml', ], 'installable': True, 'application': True, diff --git a/addons/locadis/static/src/css/pos.css b/addons/locadis/static/src/css/pos.css index d9ec3ba7cee..075b4dccc27 100644 --- a/addons/locadis/static/src/css/pos.css +++ b/addons/locadis/static/src/css/pos.css @@ -1,4 +1,6 @@ - +.point-of-sale .screen p{ + font-size: 24px; +} .product-list-empty{ text-align:center; } diff --git a/addons/locadis/static/src/xml/pos.xml b/addons/locadis/static/src/xml/pos.xml index f69c3b788df..5ce23396db8 100644 --- a/addons/locadis/static/src/xml/pos.xml +++ b/addons/locadis/static/src/xml/pos.xml @@ -4,12 +4,11 @@
-

Please scan an item

+

Please scan your products

- From e6136314ee05980d80613da39d3b871096231b78 Mon Sep 17 00:00:00 2001 From: "Twinkle Christian (OpenERP)" Date: Thu, 30 Aug 2012 17:42:56 +0530 Subject: [PATCH 006/173] [IMP]Replace category to tag bzr revid: tch@tinyerp.com-20120830121256-kpgxk6spojucj96e --- addons/project/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/project/project.py b/addons/project/project.py index 904e19671cb..d8457f2fb81 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -746,7 +746,7 @@ class task(base_stage, osv.osv): When the case is over, the state is set to \'Done\'.\ If the case needs to be reviewed then the state is \ set to \'Pending\'.'), - 'categ_ids': fields.many2many('project.category', string='Categories'), + 'categ_ids': fields.many2many('project.category', string='Tags'), 'kanban_state': fields.selection([('normal', 'Normal'),('blocked', 'Blocked'),('done', 'Ready To Pull')], 'Kanban State', help="A task's kanban state indicates special situations affecting it:\n" " * Normal is the default situation\n" From 7c632f13c5bb6a4a4cac6082c873ae0a34cf3032 Mon Sep 17 00:00:00 2001 From: "Twinkle Christian (OpenERP)" Date: Thu, 30 Aug 2012 17:48:04 +0530 Subject: [PATCH 007/173] [IMP]In stage object replace state to status bzr revid: tch@tinyerp.com-20120830121804-xcem0nccdmz50f3c --- addons/crm/crm_view.xml | 2 +- addons/project/project_view.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/crm/crm_view.xml b/addons/crm/crm_view.xml index b51f1288b95..8fa3927beea 100644 --- a/addons/crm/crm_view.xml +++ b/addons/crm/crm_view.xml @@ -183,7 +183,7 @@
- + diff --git a/addons/project/project_view.xml b/addons/project/project_view.xml index f864e207141..32b35a9f3f4 100644 --- a/addons/project/project_view.xml +++ b/addons/project/project_view.xml @@ -780,7 +780,7 @@ - + From 2063604ca8ead8846136dd1d9a6d4de249c40bfd Mon Sep 17 00:00:00 2001 From: "ajay javiya (OpenERP)" Date: Thu, 30 Aug 2012 18:13:55 +0530 Subject: [PATCH 008/173] [IMP]mrp:Improve ir.acrion.todo to jump mrp bzr revid: aja@tinyerp.com-20120830124355-5230z42d8f0up3sp --- addons/mrp/res_config_view.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/mrp/res_config_view.xml b/addons/mrp/res_config_view.xml index 4d94e611fdf..16ebbdcb05b 100644 --- a/addons/mrp/res_config_view.xml +++ b/addons/mrp/res_config_view.xml @@ -12,6 +12,9 @@ automatic 100 + + done + From 69af96255b340b14ff794826372d28ac0d0ff89c Mon Sep 17 00:00:00 2001 From: "Twinkle Christian (OpenERP)" Date: Thu, 30 Aug 2012 18:13:59 +0530 Subject: [PATCH 009/173] [IMP]In stage object replace state to status bzr revid: tch@tinyerp.com-20120830124359-yidn3iwmcq2ubnal --- addons/crm/crm.py | 2 +- addons/crm_claim/crm_claim.py | 2 +- addons/hr_recruitment/hr_recruitment.py | 2 +- addons/project/project.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index b45b8ea8712..b862e977c9a 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -75,7 +75,7 @@ class crm_case_stage(osv.osv): 'requirements': fields.text('Requirements'), 'section_ids':fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', string='Sections', help="Link between stages and sales teams. When set, this limitate the current stage to the selected sales teams."), - 'state': fields.selection(AVAILABLE_STATES, 'State', required=True, help="The related state for the stage. The state of your document will automatically change regarding the selected stage. For example, if a stage is related to the state 'Close', when your document reaches this stage, it will be automatically have the 'closed' state."), + 'state': fields.selection(AVAILABLE_STATES, 'State', required=True, help="The related status for the stage. The state of your document will automatically change regarding the selected stage. For example, if a stage is related to the state 'Close', when your document reaches this stage, it will be automatically have the 'closed' state."), 'case_default': fields.boolean('Common to All Teams', help="If you check this field, this stage will be proposed by default on each sales team. It will not assign this stage to existing teams."), 'fold': fields.boolean('Hide in Views when Empty', diff --git a/addons/crm_claim/crm_claim.py b/addons/crm_claim/crm_claim.py index ec6252bcdca..ba45c95d065 100644 --- a/addons/crm_claim/crm_claim.py +++ b/addons/crm_claim/crm_claim.py @@ -49,7 +49,7 @@ class crm_claim_stage(osv.osv): 'sequence': fields.integer('Sequence', help="Used to order stages. Lower is better."), 'section_ids':fields.many2many('crm.case.section', 'section_claim_stage_rel', 'stage_id', 'section_id', string='Sections', help="Link between stages and sales teams. When set, this limitate the current stage to the selected sales teams."), - 'state': fields.selection(crm.AVAILABLE_STATES, 'State', required=True, help="The related state for the stage. The state of your document will automatically change regarding the selected stage. For example, if a stage is related to the state 'Close', when your document reaches this stage, it will be automatically have the 'closed' state."), + 'state': fields.selection(crm.AVAILABLE_STATES, 'State', required=True, help="The related status for the stage. The state of your document will automatically change regarding the selected stage. For example, if a stage is related to the state 'Close', when your document reaches this stage, it will be automatically have the 'closed' state."), 'case_refused': fields.boolean('Refused stage', help='Refused stages are specific stages for done.'), 'case_default': fields.boolean('Common to All Teams', diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 6b4839b7b2b..4ddc91fc519 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -61,7 +61,7 @@ class hr_recruitment_stage(osv.osv): 'name': fields.char('Name', size=64, required=True, translate=True), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of stages."), 'department_id':fields.many2one('hr.department', 'Specific to a Department', help="Stages of the recruitment process may be different per department. If this stage is common to all departments, keep this field empty."), - 'state': fields.selection(AVAILABLE_STATES, 'State', required=True, help="The related state for the stage. The state of your document will automatically change according to the selected stage. Example, a stage is related to the state 'Close', when your document reach this stage, it will be automatically closed."), + 'state': fields.selection(AVAILABLE_STATES, 'State', required=True, help="The related status for the stage. The state of your document will automatically change according to the selected stage. Example, a stage is related to the state 'Close', when your document reach this stage, it will be automatically closed."), 'fold': fields.boolean('Hide in views if empty', help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."), 'requirements': fields.text('Requirements'), } diff --git a/addons/project/project.py b/addons/project/project.py index 904e19671cb..6f6207de27c 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -41,7 +41,7 @@ class project_task_type(osv.osv): help="If you check this field, this stage will be proposed by default on each new project. It will not assign this stage to existing projects."), 'project_ids': fields.many2many('project.project', 'project_task_type_rel', 'type_id', 'project_id', 'Projects'), 'state': fields.selection(_TASK_STATE, 'State', required=True, - help="The related state for the stage. The state of your document will automatically change regarding the selected stage. Example, a stage is related to the state 'Close', when your document reach this stage, it will be automatically closed."), + help="The related status for the stage. The state of your document will automatically change regarding the selected stage. Example, a stage is related to the state 'Close', when your document reach this stage, it will be automatically closed."), 'fold': fields.boolean('Hide in views if empty', help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."), } From 3a9b697e9cafb41d3cfeef4f2095a7a3e37562b6 Mon Sep 17 00:00:00 2001 From: "Twinkle Christian (OpenERP)" Date: Thu, 30 Aug 2012 18:31:19 +0530 Subject: [PATCH 010/173] [IMP]In stage object replace state to status bzr revid: tch@tinyerp.com-20120830130119-o1ofjtiwuhlmbu2x --- addons/mrp/res_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/res_config.py b/addons/mrp/res_config.py index 555010c2be1..34717d985c0 100644 --- a/addons/mrp/res_config.py +++ b/addons/mrp/res_config.py @@ -65,7 +65,7 @@ class mrp_config_settings(osv.osv_memory): help="""Routings allow you to create and manage the manufacturing operations that should be followed within your work centers in order to produce a product. They are attached to bills of materials that will define the required raw materials."""), - 'group_mrp_properties': fields.boolean("allow several bill of materials per products", + 'group_mrp_properties': fields.boolean("allow several bill of materials per products using properties", implied_group='product.group_mrp_properties', help="""The selection of the right Bill of Material to use will depend on the properties specified on the sale order and the Bill of Material."""), 'module_product_manufacturer': fields.boolean("define manufacturers on products ", From 3f2ced5a06fe5f47dc813399efadcf4a9bdd592b Mon Sep 17 00:00:00 2001 From: "ajay javiya (OpenERP)" Date: Thu, 30 Aug 2012 18:33:59 +0530 Subject: [PATCH 011/173] [IMP]mrp:change default supply method bzr revid: aja@tinyerp.com-20120830130359-bslgfmtvoqcl12hf --- addons/mrp/mrp_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index 99c8befbb6c..d7d59d5cfdd 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -649,7 +649,7 @@
From f9c81acefd981c4912e92e605ef0a34ecfe665a8 Mon Sep 17 00:00:00 2001 From: "ajay javiya (OpenERP)" Date: Tue, 4 Sep 2012 16:52:50 +0530 Subject: [PATCH 040/173] [IMP]: Improve form view bzr revid: aja@tinyerp.com-20120904112250-2lmwv8xi6uwt086j --- addons/mrp/mrp_view.xml | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index 6aa79bcd2b7..5db5d8cbc97 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -345,32 +345,31 @@ mrp.bom -