Merge lp:~sylvain-legal/openupgrade-addons/7.0_point_of_sale into lp:openupgrade-addons

Proposed by Sylvain LE GAL (GRAP)
Status: Work in progress
Proposed branch: lp:~sylvain-legal/openupgrade-addons/7.0_point_of_sale
Merge into: lp:openupgrade-addons
Diff against target: 416 lines (+397/-0)
4 files modified
point_of_sale/migrations/7.0.1.0.1/openupgrade_analysis_work.txt (+169/-0)
point_of_sale/migrations/7.0.1.0.1/post-migration.py (+180/-0)
point_of_sale/migrations/7.0.1.0.1/pre-migration.py (+34/-0)
point_of_sale/migrations/7.0.1.0.1/user_notes.txt (+14/-0)
To merge this branch: bzr merge lp:~sylvain-legal/openupgrade-addons/7.0_point_of_sale
Reviewer Review Type Date Requested Status
OpenUpgrade Committers Pending
Review via email: mp+187221@code.launchpad.net

Description of the change

This branch will manage 'point_of_sale' migration.
Work in progress.
Please don't review until the state changes.
Merge Proposal just to inform to community i'm working on the module.

To post a comment you must log in.
8137. By Sylvain LE GAL (GRAP)

[ADD] First version Beta for 'point_of_sale' migration.

Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

My apologize for the mistake.

2013/10/15 Sylvain LE GAL (GRAP) <email address hidden>

> The proposal to merge
> lp:~sylvain-legal/openupgrade-addons/7.0_point_of_sale into
> lp:openupgrade-addons has been updated.
>
> Status: Merged => Work in progress
>
> For more details, see:
>
> https://code.launchpad.net/~sylvain-legal/openupgrade-addons/7.0_point_of_sale/+merge/187221
> --
>
> https://code.launchpad.net/~sylvain-legal/openupgrade-addons/7.0_point_of_sale/+merge/187221
> You are the owner of
> lp:~sylvain-legal/openupgrade-addons/7.0_point_of_sale.
>

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

How is this work going, Sylvain?

Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Hi,

I realized a migration 6.1 -> 7.0 in November 2013 with this script. I did'nt marked this MP as 'ready to review' because this script was experimental and I think that other developpers have to work on it to make it more correct maybe.
I kept it in the state 'work in progress' because maybe this script can be usefull for any people.

Regards.

Unmerged revisions

8137. By Sylvain LE GAL (GRAP)

[ADD] First version Beta for 'point_of_sale' migration.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'point_of_sale/migrations/7.0.1.0.1/openupgrade_analysis_work.txt'
--- point_of_sale/migrations/7.0.1.0.1/openupgrade_analysis_work.txt 1970-01-01 00:00:00 +0000
+++ point_of_sale/migrations/7.0.1.0.1/openupgrade_analysis_work.txt 2013-10-14 23:49:02 +0000
@@ -0,0 +1,169 @@
1# - se faire une base de référence de point of sale en 6.1
2# passer une migration V7 avec rien, pour voir comment ça réagit.
3
4
5---Fields in module 'point_of_sale'---
6### Create an session for each bank statement.
7point_of_sale / account.bank.statement / pos_session_id (many2one) : NEW relation: pos.session
8
9### Deleting a field related. Nothing to do.
10point_of_sale / account.bank.statement.line / journal_id (char) : DEL mode: modify
11
12
13### This concept are lost in V7. Nothing to do.
14point_of_sale / account.journal / auto_cash (boolean) : DEL
15point_of_sale / account.journal / check_dtls (boolean) : DEL
16### New concept, use default
17point_of_sale / account.journal / amount_authorized_diff (float): NEW
18point_of_sale / account.journal / self_checkout_payment_method (boolean): NEW
19
20### New concept. hypothesis : create au new pos_config object for each shop_id / sale_journal / user_id
21point_of_sale / pos.config / group_by (boolean) : NEW
22point_of_sale / pos.config / iface_cashdrawer (boolean) : NEW
23point_of_sale / pos.config / iface_electronic_scale (boolean): NEW
24point_of_sale / pos.config / iface_payment_terminal (boolean): NEW
25point_of_sale / pos.config / iface_print_via_proxy (boolean): NEW
26point_of_sale / pos.config / iface_self_checkout (boolean) : NEW
27point_of_sale / pos.config / iface_vkeyboard (boolean) : NEW
28point_of_sale / pos.config / journal_id (many2one) : NEW relation: account.journal
29point_of_sale / pos.config / journal_ids (many2many) : NEW relation: account.journal
30point_of_sale / pos.config / name (char) : NEW required: required
31point_of_sale / pos.config / sequence_id (many2one) : NEW relation: ir.sequence
32point_of_sale / pos.config / session_ids (one2many) : NEW relation: pos.session
33point_of_sale / pos.config / shop_id (many2one) : NEW relation: sale.shop, required: required, req_default: function
34point_of_sale / pos.config / state (selection) : NEW required: required, selection_keys: ['active', 'deprecated', 'inactive'], req_default: active
35
36# Pour les pos_order faire un select shop_id, sale_journal. Créer un pos_config & des pos_sessions associés. !!!! Attention aussi aux users.
37
38# New optional value. Nothing to do.
39point_of_sale / pos.order / pos_reference (char) : NEW
40### The script migration will associate a pos.order to a new 'pos.session'. (associated to sale_journal).
41# No Data loss neither, data Change. Nothing to do.
42point_of_sale / pos.order / sale_journal (many2one) : now a function
43# The script migration will associate a pos.order to a new 'pos.session'.
44point_of_sale / pos.order / session_id (many2one) : NEW relation: pos.session
45### The script migration will associate a pos.order to a new 'pos.session'. (associated to shop_id).
46# No Data loss neither, data Change. Nothing to do.
47point_of_sale / pos.order / shop_id (many2one) : now a function
48
49
50point_of_sale / pos.session / config_id (many2one) : NEW relation: pos.config, required: required
51point_of_sale / pos.session / name (char) : NEW required: required, req_default: /
52point_of_sale / pos.session / order_ids (one2many) : NEW relation: pos.order
53point_of_sale / pos.session / start_at (datetime) : NEW
54point_of_sale / pos.session / state (selection) : NEW required: required, selection_keys: ['closed', 'closing_control', 'opened', 'opening_control'], req_default: opening_control
55point_of_sale / pos.session / statement_ids (one2many) : NEW relation: account.bank.statement
56point_of_sale / pos.session / stop_at (datetime) : NEW
57point_of_sale / pos.session / user_id (many2one) : NEW relation: res.users, required: required, req_default: function
58
59### 'available_in_pos' is a new concept. If checked, the product will be available to sale in the point of sale.
60# In 6.1, the product was available if the product had a pos_categ_id defined.
61# The script migration will set to True the 'available_in_pos' value for all product with a pos_categ_id defined.
62point_of_sale / product.product / available_in_pos (boolean) : NEW
63
64### 'to_weight' is a a new concept. We assume that all products that have a unit 'uos_id' (or 'uom_id') which 'uom_categ_id' is 'product_uom_categ_kgm' can be weight.
65# The script migration will set to True the 'to_weight' value for that products.
66## USE : uom_categ, uom_categ_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'product_uom_categ_kgm')
67point_of_sale / product.product / to_weight (boolean) : NEW
68
69# New Concept for 'pos.category'. Nothing to do.
70point_of_sale / pos.category / image (binary) : NEW
71
72# New Concept for 'res_user'. Nothing to do.
73point_of_sale / res.users / ean13 (char) : NEW
74
75# Script migration will associate a new 'pos.config' to each sale user.
76point_of_sale / res.users / pos_config (many2one) : NEW relation: pos.config
77
78---XML records in module 'point_of_sale'---
79### Ignore interface and access records
80NEW ir.actions.act_window: point_of_sale.act_pos_config_sessions
81NEW ir.actions.act_window: point_of_sale.act_pos_session_orders
82NEW ir.actions.act_window: point_of_sale.action_pos_box_in
83NEW ir.actions.act_window: point_of_sale.action_pos_box_out
84NEW ir.actions.act_window: point_of_sale.action_pos_config_pos
85NEW ir.actions.act_window: point_of_sale.action_pos_session
86NEW ir.actions.act_window: point_of_sale.action_pos_session_opening
87DEL ir.actions.act_window: point_of_sale.action_box_entries
88DEL ir.actions.act_window: point_of_sale.action_box_out
89DEL ir.actions.act_window: point_of_sale.action_pos_close_statement
90DEL ir.actions.act_window: point_of_sale.action_pos_confirm
91DEL ir.actions.act_window: point_of_sale.action_pos_sale_all
92DEL ir.actions.act_window: point_of_sale.action_product_input
93DEL ir.actions.act_window: point_of_sale.action_product_output
94DEL ir.actions.act_window: point_of_sale.action_report_cash_register_all
95NEW ir.actions.client: point_of_sale.action_client_pos_menu
96NEW ir.actions.report.xml: point_of_sale.report_user_label
97NEW ir.actions.todo: base.open_menu
98NEW ir.model.access: point_of_sale.access_account_journal_cashbox_line
99NEW ir.model.access: point_of_sale.access_ir_sequence_manager
100NEW ir.model.access: point_of_sale.access_pos_config_user
101NEW ir.model.access: point_of_sale.access_pos_session_user
102DEL ir.model.access: point_of_sale.access_account_journal_column
103DEL ir.model.access: point_of_sale.access_account_journal_column_manager
104DEL ir.model.access: point_of_sale.access_account_journal_view
105DEL ir.model.access: point_of_sale.access_account_journal_view_manager
106DEL ir.model.access: point_of_sale.access_pos_config_journal
107DEL ir.model.access: point_of_sale.access_pos_config_journal_manager
108DEL ir.model.access: point_of_sale.access_report_check_register
109NEW ir.rule: point_of_sale.rule_pos_multi_company
110NEW ir.ui.menu: point_of_sale.menu_pos_config_pos
111NEW ir.ui.menu: point_of_sale.menu_pos_session_all
112NEW ir.ui.menu: point_of_sale.menu_pos_session_opening
113DEL ir.ui.menu: point_of_sale.menu_all_menu_all_register
114DEL ir.ui.menu: point_of_sale.menu_close_statement
115DEL ir.ui.menu: point_of_sale.menu_open_statement
116DEL ir.ui.menu: point_of_sale.menu_point_ofsale_all
117DEL ir.ui.menu: point_of_sale.menu_point_open_config
118DEL ir.ui.menu: point_of_sale.menu_point_root_touchscreen
119DEL ir.ui.menu: point_of_sale.menu_report_cash_register_all
120DEL ir.ui.menu: point_of_sale.menu_wizard_enter_jrnl
121DEL ir.ui.menu: point_of_sale.menu_wizard_enter_jrnl2
122DEL ir.ui.menu: point_of_sale.menu_wizard_pos_confirm
123DEL ir.ui.menu: point_of_sale.products_for_input_operations
124DEL ir.ui.menu: point_of_sale.products_for_output_operations
125NEW ir.ui.view: point_of_sale.pos_ean13_generator
126NEW ir.ui.view: point_of_sale.pos_session_opening_form_view
127NEW ir.ui.view: point_of_sale.res_users_form_preference_view
128NEW ir.ui.view: point_of_sale.res_users_form_view
129NEW ir.ui.view: point_of_sale.view_partner_property_form
130NEW ir.ui.view: point_of_sale.view_pos_config_form
131NEW ir.ui.view: point_of_sale.view_pos_config_search
132NEW ir.ui.view: point_of_sale.view_pos_config_tree
133NEW ir.ui.view: point_of_sale.view_pos_session_form
134NEW ir.ui.view: point_of_sale.view_pos_session_search
135NEW ir.ui.view: point_of_sale.view_pos_session_tree
136DEL ir.ui.view: point_of_sale.product_normal_form_pos_view
137DEL ir.ui.view: point_of_sale.view_box_entries
138DEL ir.ui.view: point_of_sale.view_pos_box_out
139DEL ir.ui.view: point_of_sale.view_pos_close_statement
140DEL ir.ui.view: point_of_sale.view_report_cash_register_search
141DEL ir.ui.view: point_of_sale.view_report_cash_register_tree
142
143### Ignore new sequence records
144NEW ir.sequence: point_of_sale.seq_pos_session
145NEW ir.sequence.type: point_of_sale.seq_type_pos_session
146
147### Ignore added chatter configuration
148NEW mail.message: point_of_sale.module_install_notification
149
150### New pos_config. script migration will set it in a obsolete state.
151NEW pos.config: point_of_sale.pos_config_main
152
153### New product. Nothing to do.
154NEW product.product: point_of_sale.unreferenced_product
155
156### Completely new workflow for 'pos.dession'. Nothing to do.
157NEW workflow: point_of_sale.wkf_pos_session
158NEW workflow.activity: point_of_sale.act_close
159NEW workflow.activity: point_of_sale.act_closing_control
160NEW workflow.activity: point_of_sale.act_open
161NEW workflow.activity: point_of_sale.act_opening_control
162NEW workflow.activity: point_of_sale.act_start
163NEW workflow.transition: point_of_sale.trans_closing_control_to_close
164NEW workflow.transition: point_of_sale.trans_closing_control_to_close_no_control
165NEW workflow.transition: point_of_sale.trans_open_to_close
166NEW workflow.transition: point_of_sale.trans_open_to_closing_control
167NEW workflow.transition: point_of_sale.trans_opening_control_to_open
168NEW workflow.transition: point_of_sale.trans_start_to_open
169NEW workflow.transition: point_of_sale.trans_start_to_opening_control
0170
=== added file 'point_of_sale/migrations/7.0.1.0.1/post-migration.py'
--- point_of_sale/migrations/7.0.1.0.1/post-migration.py 1970-01-01 00:00:00 +0000
+++ point_of_sale/migrations/7.0.1.0.1/post-migration.py 2013-10-14 23:49:02 +0000
@@ -0,0 +1,180 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2013 Sylvain LE GAL
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21from openerp import pooler, SUPERUSER_ID
22from openerp.openupgrade import openupgrade, openupgrade_70
23
24def migrate_product_available_in_pos(cr, pool):
25 """
26 Initialize product that available_in_pos, using old behaviour of
27 6.1 version. (In 6.1, product with pos_categ_id set are available in pos)
28 """
29 cr.execute("""UPDATE product_product
30 SET available_in_pos = True
31 WHERE pos_categ_id is not Null""")
32
33def migrate_product_to_weight(cr, pool):
34 """
35 Initialize product_to_weight value in 'product.product', assuming that
36 product that have an uom weightable will be 'product_to_weight'.
37 """
38 product_product_obj = pool.get('product.product')
39 uom_categ, uom_categ_id = pool.get('ir.model.data').get_object_reference(
40 cr, SUPERUSER_ID, 'product', 'product_uom_categ_kgm')
41 uom_ids = pool.get('product.uom').search(cr, SUPERUSER_ID,
42 [('category_id', '=', uom_categ_id)])
43 product_ids = product_product_obj.search(cr, SUPERUSER_ID,
44 [('uom_id', 'in', uom_ids)])
45 product_product_obj.write(cr, SUPERUSER_ID,
46 product_ids,
47 {'to_weight' : True,})
48
49def create_pos_config(cr, pool):
50 """
51 pos_config is totally new concept.
52 Script migration will create pos_config based on datas in point_of_sale (6.1)
53 (One pos_config by shop and sale_journal in 6.1.)
54 Script migration will create too on pos_config by sale user because it's not
55 possible to create 2 pos.session active with the same 'pos.config'.
56 """
57 pos_config_obj = pool.get('pos.config')
58 shop_obj = pool.get('sale.shop')
59 journal_obj = pool.get('account.journal')
60 user_obj = pool.get('res.users')
61 pos_session_obj = pool.get('pos.session')
62 pos_order_obj = pool.get('pos.order')
63 # Create a pos config by shop, and sale_journal
64 cr.execute("""
65 SELECT shop_id, sale_journal sale_journal_id, user_id
66 FROM pos_order
67 GROUP BY shop_id, sale_journal, user_id;""")
68
69 for shop_id, sale_journal_id, user_id in cr.fetchall():
70 # Generate a readable name
71 name = shop_obj.read(cr, SUPERUSER_ID, [shop_id], ['name'])[0]['name']
72 name += " - " + journal_obj.read(cr, SUPERUSER_ID, [sale_journal_id], ['code'])[0]['code']
73 name += " - " + user_obj.read(cr, SUPERUSER_ID, [user_id], ['login'])[0]['login']
74
75 # Get the bank_journal related to new pos_config, using the history of pos_orders.
76 cr.execute("""
77 SELECT abs.journal_id bank_journal_id
78 FROM account_bank_statement_line absl
79 INNER JOIN account_bank_statement abs ON abs.id = absl.statement_id
80 INNER JOIN pos_order po ON absl.pos_statement_id= po.id
81 WHERE po.shop_id = {0} and po.sale_journal = {1}
82 GROUP BY abs.journal_id; """.format(shop_id, sale_journal_id))
83
84 bank_journal_ids = []
85 for bank_journal_id in cr.fetchall():
86 bank_journal_ids.append(bank_journal_id[0])
87 pos_config_id = pos_config_obj.create(cr, SUPERUSER_ID, {
88 'name' : name,
89 'journal_id': sale_journal_id,
90 'shop_id': shop_id,
91 'journal_ids' : [(6,0,bank_journal_ids)],
92 })
93
94 # associate user to new pos_config.
95 user_obj.write(cr, SUPERUSER_ID, [user_id], {'pos_config' : pos_config_id})
96
97 # Get all statement_id associated to a pos.session.
98 cr.execute("""
99 SELECT absl.statement_id from account_bank_statement_line absl
100 INNER JOIN pos_order po on po.id = absl.pos_statement_id
101 WHERE po.shop_id={0} AND po.user_id={1} AND po.sale_journal={2}
102 GROUP BY absl.statement_id;
103 """.format(shop_id, sale_journal_id, user_id))
104 statement_ids = []
105 for statement_id in cr.fetchall():
106 statement_ids.append(statement_id[0])
107
108 # create pos session by sql, to avoid automatic creation of account bank statement
109 # and other behaviours not wished
110 cr.execute("""
111 INSERT INTO pos_session(
112 create_uid, create_date, write_uid, write_date,
113 config_id, user_id, name, state,
114 start_at, stop_at, cash_journal_id, cash_register_id
115 )
116 VALUES (
117 {0}, {1}, {0}, {1},
118 {2}, {0}, '{3}', 'closed',
119 Null, Null, Null, Null)
120 RETURNING id;
121 """.format(user_id,
122 "(now() at time zone 'UTC')",
123 pos_config_id,
124 name.encode('utf-8').strip(),
125 ))
126 pos_session_id = cr.fetchone()[0]
127 if statement_ids !=[]:
128 #import pdb; pdb.set_trace()
129 for sub_ids in cr.split_for_in_conditions(statement_ids):
130 cr.execute("""
131 UPDATE account_bank_statement
132 SET pos_session_id = %s
133 WHERE id in %%s
134 """ % (pos_session_id), [tuple(sub_ids)])
135# pos_session_id = pos_session_obj.create(cr, SUPERUSER_ID, {
136# 'config_id' : pos_config_id,
137# 'start_at' : None,
138# 'state' : 'closed',
139# 'statement_ids' : [(6,0,statement_ids)],
140# 'stop_at' : None,
141# 'user_id' : user_id,
142# })
143
144 # associate pos.order to the new pos.session
145 cr.execute("""
146 UPDATE pos_order
147 SET session_id={3}
148 WHERE shop_id={0} AND sale_journal={1} AND user_id={2};
149 """.format(shop_id, sale_journal_id, user_id, pos_session_id))
150
151# cr.execute("""
152# SELECT id
153# FROM pos_order
154# WHERE shop_id={0} AND sale_journal={1} AND user_id={2};
155# """.format(shop_id, sale_journal_id, user_id))
156# pos_order_ids = []
157# for pos_order_id in cr.fetchall():
158# pos_order_ids.append(pos_order_id[0])
159#
160# pos_order_obj.write(cr, SUPERUSER_ID, pos_order_ids, {'session_id' : pos_session_id})
161
162def disable_default_pos_config(cr, pool):
163 pass
164 pos_config, pos_config_id = pool.get('ir.model.data').get_object_reference(
165 cr, SUPERUSER_ID, 'point_of_sale', 'pos_config_main')
166 pool.get('pos.config').write(cr, SUPERUSER_ID,
167 [pos_config_id],
168 {'state' : 'inactive'})
169
170
171@openupgrade.migrate()
172def migrate(cr, version):
173 pool = pooler.get_pool(cr.dbname)
174 migrate_product_available_in_pos(cr, pool)
175 migrate_product_to_weight(cr, pool)
176 # create new pos_config
177 create_pos_config(cr, pool)
178
179 # disable old default pos_config
180 disable_default_pos_config(cr, pool)
0181
=== added file 'point_of_sale/migrations/7.0.1.0.1/pre-migration.py'
--- point_of_sale/migrations/7.0.1.0.1/pre-migration.py 1970-01-01 00:00:00 +0000
+++ point_of_sale/migrations/7.0.1.0.1/pre-migration.py 2013-10-14 23:49:02 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2013 Sylvain LE GAL
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.openupgrade import openupgrade
23
24column_renames = {
25}
26
27xmlid_renames = [
28]
29
30
31@openupgrade.migrate()
32def migrate(cr, version):
33 openupgrade.rename_columns(cr, column_renames)
34 openupgrade.rename_xmlids(cr, xmlid_renames)
035
=== added file 'point_of_sale/migrations/7.0.1.0.1/user_notes.txt'
--- point_of_sale/migrations/7.0.1.0.1/user_notes.txt 1970-01-01 00:00:00 +0000
+++ point_of_sale/migrations/7.0.1.0.1/user_notes.txt 2013-10-14 23:49:02 +0000
@@ -0,0 +1,14 @@
1Point of Sale V7 change the behaviour of the close of bank_statement.
2It's not possible in V7 to close a session if there is some unpaid pos order in the session.
3
4
5Point of sale V7 is very different. So The script migration will assume that
6The users have used the point of sale V6.1 like a point of sale V7. Specially for the following things :
7- a user can not sale (use a pos.config) if the pos.config is in use by an other user.
8So script migration will create a pos.config for each sale user.
9
10-
11
12WARNING : standart V7 doesn't allow to close a pos.session (and so associated account.bank.statement) if a pos.order is not paid in the pos.session.
13
14

Subscribers

People subscribed via source and target branches