Skip to content

Commit

Permalink
Merge pull request #1 from kirca/point_of_sale
Browse files Browse the repository at this point in the history
Point of sale
  • Loading branch information
legalsylvain committed Apr 17, 2015
2 parents 5cdd22d + e082fee commit 88e4d73
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---Fields in module 'point_of_sale'---
# In V7, there was a shop_id with a company_id (optional) TODO
# In V7, there was a shop_id with a company_id (optional) --> Done.
# - if company_id is set in V7 on shop_id -> OpenUpgrade will take the company_id of the old shop_id;
# - if company_id is not set in V7 on shop_id -> Openupgrade will raise a non blocking error by log;
# - if company_id is not set in V7 on shop_id -> Openupgrade will raise a non blocking error by log and set it to a random res.company record;
point_of_sale / pos.config / company_id (many2one) : NEW relation: res.company, required: required, req_default: function

# [3 lines] 'iface_big_scrollbars', 'iface_invoicing', 'iface_scan_via_proxy' :. New feature. NTD
point_of_sale / pos.config / iface_big_scrollbars (boolean): NEW
point_of_sale / pos.config / iface_invoicing (boolean) : NEW
point_of_sale / pos.config / iface_scan_via_proxy (boolean): NEW
# TODO: Create a new picking_type_id for each active pos_config.
# Create a new picking_type_id for each active pos_config. --> Done.
point_of_sale / pos.config / picking_type_id (many2one) : NEW relation: stock.picking.type
# TODO: keep the pricelist_id of the old sale_shop.
# keep the pricelist_id of the old sale_shop. --> Done
point_of_sale / pos.config / pricelist_id (many2one) : NEW relation: product.pricelist, required: required, req_default: function
# In v7. Value was hardcoded with http://localhost:8069. Done.
point_of_sale / pos.config / proxy_ip (char) : NEW
# [2 lines] 'receipt_footer' and 'receipt_header'. New text field. NTD.
point_of_sale / pos.config / receipt_footer (text) : NEW
point_of_sale / pos.config / receipt_header (text) : NEW
# TODO: Select the stock_location_id (internal) of the stock_warehouse of the old shop_id;
# Select the stock_location_id (internal) of the stock_warehouse of the old shop_id; --> Done.
point_of_sale / pos.config / shop_id (many2one) : DEL relation: sale.shop, required: required, req_default: function
point_of_sale / pos.config / stock_location_id (many2one) : NEW relation: stock.location, required: required, req_default: function

Expand All @@ -41,7 +41,7 @@ point_of_sale / report.pos.order / shop_id (many2one) : DEL r
point_of_sale / report.pos.order / year (char) : DEL


---XML records in module 'point_of_sale'---
---XML records in module 'point_of_sale'--- NTD
NEW ir.actions.act_url: point_of_sale.action_pos_pos
NEW ir.actions.act_window: point_of_sale.product_pos_category_action
DEL ir.actions.act_window: point_of_sale.action_pos_payment_report
Expand Down Expand Up @@ -101,10 +101,7 @@ DEL ir.ui.view: point_of_sale.view_report_sales_by_margin_pos_month_form
DEL ir.ui.view: point_of_sale.view_report_sales_by_margin_pos_month_graph
DEL ir.ui.view: point_of_sale.view_report_sales_by_margin_pos_month_tree
DEL ir.ui.view: point_of_sale.view_report_sales_by_margin_pos_tree
# TODO
DEL pos.category: point_of_sale.categ_others
# TODO
DEL product.product: point_of_sale.unreferenced_product
NEW report.paperformat: point_of_sale.paperformat_posreceipt
# TODO
NEW stock.picking.type: point_of_sale.picking_type_posout
144 changes: 129 additions & 15 deletions addons/point_of_sale/migrations/8.0.1.0.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,126 @@
#
##############################################################################

import logging
from openerp.openupgrade import openupgrade
from openerp.modules.registry import RegistryManager
from openerp import SUPERUSER_ID


logger = logging.getLogger('OpenUpgrade.point_of_sale')


def get_warehouse_id(cr, pool, shop_id):
"""
Get the sale.shop warehouse_id
"""
cr.execute(
"SELECT warehouse_id FROM sale_shop WHERE id=%s", (shop_id,))
return cr.fetchone()[0]


def get_stock_location_id(cr, pool, shop_id):
"""
Select the stock_location_id (internal) on pos.config
to be that of the stock_warehouse of the old shop_id
"""
wh_obj = pool['stock.warehouse']
return wh_obj.read(
cr, SUPERUSER_ID, [get_warehouse_id(cr, pool, shop_id)],
['lot_stock_id'])[0]['lot_stock_id'][0]


def get_company_id(cr, pool, shop_id, pc, stock_loc_id):
"""
Try to get company_id from sale.shop.
If that fails try to get from the related journal_id
or the newly added stock_location_id.
In the end set it to any res.company record.
"""
cr.execute(
"SELECT company_id FROM sale_shop WHERE id=%s", (shop_id,))
comp_id = cr.fetchone()[0]
if not comp_id:
comp_obj = pool['res.company']
comp_id = comp_obj.search(cr, SUPERUSER_ID, [])
if len(comp_id) > 1:
if pc.journal_id:
comp_id = pc.journal_id.company_id.id
else:
stock_loc_obj = pool['stock.location']
stock_loc_comp_id = stock_loc_obj.read(
cr, SUPERUSER_ID, [stock_loc_id],
['company_id'])[0]['company_id'][0]
if stock_loc_comp_id:
comp_id = stock_loc_comp_id
else:
comp_id = comp_id[0]
comp_name = comp_obj.read(
cr, SUPERUSER_ID, [comp_id], ['name'])[0]['name']
logger.error(
"Could not determine exactly company_id "
"for pos.config with (%s, %s). "
"Setting it randomly to (%s, %s)."
% (pc.id, pc.name, comp_id[0], comp_name))
else:
comp_id = comp_id[0]
return comp_id

def set_stock_location_id(cr, pool):
for pc in pc_obj.browse(cr, SUPERUSER_ID, pc_ids):
cr.execute(
"SELECT
pc.write({'proxy_ip': 'http://localhost:8069'})

def get_pricelist_id(cr, pool, shop_id, pc):
"""
Get the pricelist_id of the old sale_shop.
"""
cr.execute(
"SELECT pricelist_id FROM sale_shop WHERE id=%s", (shop_id,))
pricelist_id = cr.fetchone()
if not pricelist_id:
logger.warning(
"Could not determine pricelist_id "
"for pos.config with id=%s (%s)." % (pc.id, pc.name))
return False
return pricelist_id[0]


def get_picking_type_id(cr, pool, shop_id, pc):
"""
Create a new picking_type_id using shop info
"""
pt_obj = pool['stock.picking.type']
wh = pool['stock.warehouse'].browse(
cr, SUPERUSER_ID, get_warehouse_id(cr, pool, shop_id))
return pt_obj.create(cr, SUPERUSER_ID, {
'name': pc.name,
'sequence_id': pool['ir.model.data'].xmlid_to_res_id(
cr, SUPERUSER_ID, 'point_of_sale.seq_picking_type_posout'),
'code': 'outgoing',
'warehouse_id': wh.id,
'default_location_src_id': wh.wh_output_stock_loc_id.id,
'default_location_dest_id': pool['ir.model.data'].xmlid_to_res_id(
cr, SUPERUSER_ID, 'stock.stock_location_customers'),
})


def migrate_pos_config(cr, pool):
pc_obj = pool['pos.config']
pc_ids = pc_obj.search(cr, SUPERUSER_ID, [])
for pc in pc_obj.browse(cr, SUPERUSER_ID, pc_ids):
cr.execute("""
SELECT %s
FROM pos_config
WHERE id = %d
""" % (openupgrade.get_legacy_name('shop_id'), pc.id))
shop_id = cr.fetchone()[0]
stock_loc_id = get_stock_location_id(cr, pool, shop_id)
vals = {
'stock_location_id': stock_loc_id,
'company_id': get_company_id(cr, pool, shop_id, pc, stock_loc_id),
'picking_type_id': get_picking_type_id(cr, pool, shop_id, pc),
}
pricelist_id = get_pricelist_id(cr, pool, shop_id, pc)
if pricelist_id:
vals.update({'pricelist_id': pricelist_id})
pc.write(vals)


def available_in_pos_field_func(cr, pool, id, vals):
Expand Down Expand Up @@ -62,35 +174,37 @@ def set_proxy_ip(cr, pool):
pc_obj = pool['pos.config']
pc_ids = pc_obj.search(cr, SUPERUSER_ID, [])
for pc in pc_obj.browse(cr, SUPERUSER_ID, pc_ids):
if pc.iface_cashdrawer or pc.iface_payment_terminal \
or pc.iface_electronic_scale or pc.iface_print_via_proxy:
if (
pc.iface_cashdrawer or pc.iface_payment_terminal
or pc.iface_electronic_scale or pc.iface_print_via_proxy
):
pc.write({'proxy_ip': 'http://localhost:8069'})


@openupgrade.migrate()
def migrate(cr, version):
pool = pooler.get_pool(cr.dbname)
get_legacy_name = openupgrade.get_legacy_name
openupgrade.move_field_many_values_to_one(
pool = RegistryManager.get(cr.dbname)
openupgrade.move_field_m2o(
cr, pool,
'product.product', openupgrade.get_legacy_name('available_in_pos'),
'product_tmpl_id', 'product.template', 'available_in_pos',
compute_func=available_in_pos_field_func)
openupgrade.move_field_many_values_to_one(
openupgrade.move_field_m2o(
cr, pool,
'product.product', openupgrade.get_legacy_name('expense_pdt'),
'product_tmpl_id', 'product.template', 'expense_pdt',
compute_func=expense_pdt_field_func)
openupgrade.move_field_many_values_to_one(
openupgrade.move_field_m2o(
cr, pool, 'product.product', openupgrade.get_legacy_name('income_pdt'),
'product_tmpl_id', 'product.template', 'income_pdt',
compute_func=income_pdt_field_func)
openupgrade.move_field_many_values_to_one(
openupgrade.move_field_m2o(
cr, pool,
'product.product', openupgrade.get_legacy_name('pos_categ_id'),
'product_tmpl_id', 'product.template', 'pos_categ_id')
openupgrade.move_field_many_values_to_one(
openupgrade.move_field_m2o(
cr, pool, 'product.product', openupgrade.get_legacy_name('to_weight'),
'product_tmpl_id', 'product.template', 'to_weight',
compute_func=to_weight_field_func)
set_proxy_ip(cr, pool)

migrate_pos_config(cr, pool)

0 comments on commit 88e4d73

Please sign in to comment.