import time
import openerp
-from openerp import netsvc, tools
+from openerp import tools
from openerp.osv import fields, osv
from openerp.tools.translate import _
('deprecated', 'Deprecated')
]
+ def _get_currency(self, cr, uid, ids, fieldnames, args, context=None):
+ result = dict.fromkeys(ids, False)
+ for pos_config in self.browse(cr, uid, ids, context=context):
+ if pos_config.journal_id:
+ currency_id = pos_config.journal_id.currency.id or pos_config.journal_id.company_id.currency_id.id
+ else:
+ currency_id = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.currency_id.id
+ result[pos_config.id] = currency_id
+ return result
+
_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 ), ('type', 'in', ['bank', 'cash'])]",),
- 'shop_id' : fields.many2one('sale.shop', 'Shop',
+ 'warehouse_id' : fields.many2one('stock.warehouse', 'Warehouse',
required=True),
'journal_id' : fields.many2one('account.journal', 'Sale Journal',
domain=[('type', '=', 'sale')],
help="Accounting journal used to post sales entries."),
+ 'currency_id' : fields.function(_get_currency, type="many2one", string="Currency", relation="res.currency"),
'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'),
+ 'iface_cashdrawer' : fields.boolean('Cashdrawer',help="Automatically open the cashdrawer"),
+ 'iface_payment_terminal' : fields.boolean('Payment Terminal', help="Enables Payment Terminal integration"),
+ 'iface_electronic_scale' : fields.boolean('Electronic Scale', help="Enables Electronic Scale integration"),
+ 'iface_vkeyboard' : fields.boolean('Virtual KeyBoard', help="Enables an integrated Virtual Keyboard"),
+ 'iface_print_via_proxy' : fields.boolean('Print via Proxy', help="Bypass browser printing and prints via the hardware proxy"),
+ 'iface_scan_via_proxy' : fields.boolean('Scan via Proxy', help="Enable barcode scanning with a remotely connected barcode scanner"),
+ 'iface_invoicing': fields.boolean('Invoicing',help='Enables invoice generation from the Point of Sale'),
+ 'iface_big_scrollbars': fields.boolean('Large Scrollbars',help='For imprecise industrial touchscreens'),
+ 'receipt_header': fields.text('Receipt Header',help="A short text that will be inserted as a header in the printed receipt"),
+ 'receipt_footer': fields.text('Receipt Footer',help="A short text that will be inserted as a footer in the printed receipt"),
+ 'proxy_ip': fields.char('IP Address', help='The hostname or ip address of the hardware proxy, Will be autodetected if left empty', size=45),
'state' : fields.selection(POS_CONFIG_STATE, 'Status', required=True, readonly=True),
'sequence_id' : fields.many2one('ir.sequence', 'Order IDs Sequence', readonly=True,
"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"),
+ 'pricelist_id': fields.many2one('product.pricelist','Pricelist', required=True)
}
def _check_cash_control(self, cr, uid, ids, context=None):
res = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'sale'), ('company_id', '=', company_id)], limit=1, context=context)
return res and res[0] or False
- def _default_shop(self, cr, uid, context=None):
- res = self.pool.get('sale.shop').search(cr, uid, [])
+ def _default_warehouse(self, cr, uid, context=None):
+ user = self.pool.get('res.users').browse(cr, uid, uid, context)
+ res = self.pool.get('stock.warehouse').search(cr, uid, [('company_id', '=', user.company_id.id)], limit=1, context=context)
+ return res and res[0] or False
+
+ def _default_pricelist(self, cr, uid, context=None):
+ res = self.pool.get('product.pricelist').search(cr, uid, [('type', '=', 'sale')], limit=1, context=context)
return res and res[0] or False
_defaults = {
'state' : POS_CONFIG_STATE[0][0],
- 'shop_id': _default_shop,
+ 'warehouse_id': _default_warehouse,
'journal_id': _default_sale_journal,
'group_by' : True,
+ 'pricelist_id': _default_pricelist,
+ 'iface_invoicing': True,
}
def set_active(self, cr, uid, ids, context=None):
readonly=True,
states={'opening_control' : [('readonly', False)]}
),
+ 'currency_id' : fields.related('config_id', 'currency_id', type="many2one", relation='res.currency', string="Currnecy"),
'start_at' : fields.datetime('Opening Date', readonly=True),
'stop_at' : fields.datetime('Closing Date', readonly=True),
type='float',
digits_compute=dp.get_precision('Account'),
string="Ending Balance",
- help="Computed using the cash control lines",
+ help="Total of closing 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.",
+ help="Total of opening cash control lines.",
readonly=True),
'cash_register_total_entry_encoding' : fields.related('cash_register_id', 'total_entry_encoding',
string='Total Cash Transaction',
- readonly=True),
+ readonly=True,
+ help="Total of all paid sale orders"),
'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.",
+ string="Theoretical Closing Balance",
+ help="Sum of opening balance and transactions.",
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.",
+ help="Difference between the theoretical closing balance and the real closing balance.",
readonly=True),
'journal_ids' : fields.related('config_id', 'journal_ids',
# 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)
- context.update({'company_id': pos_config.shop_id.company_id.id})
+ context.update({'company_id': pos_config.warehouse_id.company_id.id})
if not pos_config.journal_id:
jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id']
if jid:
bank_values = {
'journal_id' : journal.id,
'user_id' : uid,
- 'company_id' : pos_config.shop_id.company_id.id
+ 'company_id' : pos_config.warehouse_id.company_id.id
}
statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context)
bank_statement_ids.append(statement_id)
ids = [ids]
this_record = self.browse(cr, uid, ids[0], context=context)
- this_record._workflow_signal('open')
+ this_record.signal_workflow('open')
context.update(active_id=this_record.id)
return {
- 'type' : 'ir.actions.client',
- 'name' : _('Start Point Of Sale'),
- 'tag' : 'pos.ui',
- 'context' : context,
+ 'type' : 'ir.actions.act_url',
+ 'url' : '/pos/web/',
+ 'target': 'self',
}
def wkf_action_open(self, cr, uid, ids, context=None):
}
def _confirm_orders(self, cr, uid, ids, context=None):
- wf_service = netsvc.LocalService("workflow")
-
+ account_move_obj = self.pool.get('account.move')
+ pos_order_obj = self.pool.get('pos.order')
for session in self.browse(cr, uid, ids, context=context):
local_context = dict(context or {}, force_company=session.config_id.journal_id.company_id.id)
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=local_context)
+ move_id = account_move_obj.create(cr, uid, {'ref' : session.name, 'journal_id' : session.config_id.journal_id.id, }, context=local_context)
- self.pool.get('pos.order')._create_account_move_line(cr, uid, order_ids, session, move_id, context=local_context)
+ pos_order_obj._create_account_move_line(cr, uid, order_ids, session, move_id, context=local_context)
for order in session.order_ids:
if order.state not in ('paid', 'invoiced'):
_('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)
+ pos_order_obj.signal_done(cr, uid, [order.id])
return True
_("You cannot use the session of another users. This session is owned by %s. Please first close this one to use this point of sale." % session.user_id.name))
context.update({'active_id': ids[0]})
return {
- 'type' : 'ir.actions.client',
- 'name' : _('Start Point Of Sale'),
- 'tag' : 'pos.ui',
- 'context' : context,
+ 'type' : 'ir.actions.act_url',
+ 'target': 'self',
+ 'url': '/pos/web/',
}
class pos_order(osv.osv):
_order = "id desc"
def create_from_ui(self, cr, uid, orders, context=None):
+
# Keep only new orders
submitted_references = [o['data']['name'] for o in orders]
existing_order_ids = self.search(cr, uid, [('pos_reference', 'in', submitted_references)], context=context)
existing_orders = self.read(cr, uid, existing_order_ids, ['pos_reference'], context=context)
existing_references = set([o['pos_reference'] for o in existing_orders])
orders_to_save = [o for o in orders if o['data']['name'] not in existing_references]
+
order_ids = []
for tmp_order in orders_to_save:
+ to_invoice = tmp_order['to_invoice']
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'],
'pos_reference':order['name'],
- 'partner_id': order.get('partner_id', False)
+ 'partner_id': order['partner_id'] or False
}, context)
for payments in order['statement_ids']:
payment = payments[2]
if order['amount_return']:
session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context)
cash_journal = session.cash_journal_id
- cash_statement = False
if not cash_journal:
cash_journal_ids = filter(lambda st: st.journal_id.type=='cash', session.statement_ids)
if not len(cash_journal_ids):
'journal': cash_journal.id,
}, context=context)
order_ids.append(order_id)
- wf_service = netsvc.LocalService("workflow")
+
try:
- wf_service.trg_validate(uid, 'pos.order', order_id, 'paid', cr)
- except Exception:
- _logger.error('ERROR: Could not fully process the POS Order', exc_info=True)
+ self.signal_paid(cr, uid, [order_id])
+ except Exception as e:
+ _logger.error('Could not fully process the POS Order: %s', tools.ustr(e))
+
+ if to_invoice:
+ self.action_invoice(cr, uid, [order_id], context)
+ order_obj = self.browse(cr, uid, order_id, context)
+ self.pool['account.invoice'].signal_invoice_open(cr, uid, [order_obj.invoice_id.id])
+
return order_ids
def write(self, cr, uid, ids, vals, context=None):
_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),
+ 'warehouse_id': fields.related('session_id', 'config_id', 'warehouse_id', relation='stock.warehouse', type='many2one', string='Warehouse', 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_tax': fields.function(_amount_all, string='Taxes', digits_compute=dp.get_precision('Account'), 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'),
+ 'amount_paid': fields.function(_amount_all, string='Paid', states={'draft': [('readonly', False)]}, readonly=True, digits_compute=dp.get_precision('Account'), multi='all'),
+ 'amount_return': fields.function(_amount_all, 'Returned', digits_compute=dp.get_precision('Account'), 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),
session_ids = self._default_session(cr, uid, context)
if session_ids:
session_record = self.pool.get('pos.session').browse(cr, uid, session_ids, context=context)
- shop = self.pool.get('sale.shop').browse(cr, uid, session_record.config_id.shop_id.id, context=context)
- return shop.pricelist_id and shop.pricelist_id.id or False
+ return session_record.config_id.pricelist_id and session_record.config_id.pricelist_id.id or False
return False
_defaults = {
'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
+ location_id = order.warehouse_id.lot_stock_id.id
if order.partner_id:
destination_id = order.partner_id.property_stock_customer.id
else:
'location_id': location_id if line.qty >= 0 else destination_id,
'location_dest_id': destination_id if line.qty >= 0 else location_id,
}, context=context)
-
- wf_service = netsvc.LocalService("workflow")
- wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
+
+ picking_obj.signal_button_confirm(cr, uid, [picking_id])
picking_obj.force_assign(cr, uid, [picking_id], context)
return True
@return: True
"""
stock_picking_obj = self.pool.get('stock.picking')
- wf_service = netsvc.LocalService("workflow")
for order in self.browse(cr, uid, ids, context=context):
- wf_service.trg_validate(uid, 'stock.picking', order.picking_id.id, 'button_cancel', cr)
+ stock_picking_obj.signal_button_cancel(cr, uid, [order.picking_id.id])
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 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_line['invoice_line_tax_id'] = [(6, 0, [x.id for x in line.product_id.taxes_id] )]
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)
+ self.signal_invoice(cr, uid, [order.id])
+ inv_ref.signal_validate(cr, uid, [inv_id])
if not inv_ids: return {}
# if have_to_group_by:
sale_journal_id = order.sale_journal.id
- period = account_period_obj.find(cr, uid, context=dict(context or {}, company_id=current_company.id, account_period_prefer_normal=True))[0]
+ period = account_period_obj.find(cr, uid, context=dict(context or {}, company_id=current_company.id))[0]
# 'quantity': line.qty,
# 'product_id': line.product_id.id,
_defaults = {
'user_id': lambda self,cr,uid,c={}: uid
}
-account_bank_statement()
class account_bank_statement_line(osv.osv):
_inherit = 'account.bank.statement.line'
'pos_statement_id': fields.many2one('pos.order', ondelete='cascade'),
}
-account_bank_statement_line()
class pos_order_line(osv.osv):
_name = "pos.order.line"
'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_unit': fields.float(string='Unit Price', digits_compute=dp.get_precision('Account')),
+ 'qty': fields.float('Quantity', digits_compute=dp.get_precision('Product UoS')),
'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)),
+ 'discount': fields.float('Discount (%)', digits_compute=dp.get_precision('Account')),
'order_id': fields.many2one('pos.order', 'Order Ref', ondelete='cascade'),
'create_date': fields.datetime('Creation Date', readonly=True),
}
})
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.
- # NOTE2: image: all image fields are base64 encoded and PIL-supported
- 'image': fields.binary("Image",
- help="This field holds the image used as image for the cateogry, limited to 1024x1024px."),
- '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 128x128px 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 64x64px image, with aspect ratio preserved. "\
- "Use this field anywhere a small image is required."),
- }
-
import io, StringIO
class ean_wizard(osv.osv_memory):
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})
+ self.pool[m].write(cr,uid,[m_id],{'ean13':ean13})
return { 'type' : 'ir.actions.act_window_close' }
class product_product(osv.osv):
'income_pdt': fields.boolean('Point of Sale Cash In', help="Check if, 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="Check if, this is a product you can use to take cash from a statement for the point of sale backend, example: money lost, transfer to bank, etc."),
'available_in_pos': fields.boolean('Available in the Point of Sale', help='Check if you want this product to appear in the Point of Sale'),
- 'pos_categ_id': fields.many2one('pos.category','Point of Sale Category',
- help="The Point of Sale Category this products belongs to. Those categories are used to group similar products and are specific to the Point of Sale."),
'to_weight' : fields.boolean('To Weight', help="Check if the product should be weighted (mainly used with self check-out interface)."),
}
- def _default_pos_categ_id(self, cr, uid, context=None):
- proxy = self.pool.get('ir.model.data')
-
- try:
- category_id = proxy.get_object_reference(cr, uid, 'point_of_sale', 'categ_others')[1]
- except ValueError:
- values = {
- 'name' : 'Others',
- }
- category_id = self.pool.get('pos.category').create(cr, uid, values, context=context)
- values = {
- 'name' : 'categ_others',
- 'model' : 'pos.category',
- 'module' : 'point_of_sale',
- 'res_id' : category_id,
- }
- proxy.create(cr, uid, values, context=context)
-
- return category_id
-
_defaults = {
'to_weight' : False,
'available_in_pos': True,
- 'pos_categ_id' : _default_pos_categ_id,
}
def edit_ean(self, cr, uid, ids, context):