Skip to content

Commit c86d25e

Browse files
authored
Merge pull request #2326 from ForgeFlow/13.0-mig-point_of_sale_script
[13.0][MIG] point_of_sale
2 parents b2291db + 0d7ca93 commit c86d25e

File tree

6 files changed

+477
-5
lines changed

6 files changed

+477
-5
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Copyright 2020 ForgeFlow <https://www.forgeflow.com>
2+
# Copyright 2020 Tecnativa - Pedro M. Baeza
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
from openupgradelib import openupgrade
5+
6+
7+
def create_pos_payment_methods(env):
8+
"""We will create a Payment method for each journal used on configurations"""
9+
if not openupgrade.column_exists(
10+
env.cr, "pos_payment_method", "old_journal_id"):
11+
openupgrade.logged_query(
12+
env.cr, """
13+
ALTER TABLE pos_payment_method
14+
ADD COLUMN old_journal_id int"""
15+
)
16+
env.cr.execute("""
17+
SELECT DISTINCT journal_id
18+
FROM account_bank_statement abs
19+
WHERE pos_session_id is not null
20+
""")
21+
journal_ids = [aj[0] for aj in env.cr.fetchall()]
22+
if journal_ids:
23+
openupgrade.logged_query(env.cr, """
24+
INSERT INTO pos_payment_method
25+
(
26+
old_journal_id,
27+
name,
28+
receivable_account_id,
29+
is_cash_count,
30+
cash_journal_id,
31+
company_id,
32+
create_uid,
33+
create_date,
34+
write_uid,
35+
write_date
36+
)
37+
SELECT
38+
aj.id,
39+
aj.name,
40+
rc.account_default_pos_receivable_account_id,
41+
aj.type = 'cash',
42+
CASE WHEN aj.type = 'cash' THEN aj.id ELSE NULL END,
43+
rc.id,
44+
aj.create_uid,
45+
aj.create_date,
46+
aj.write_uid,
47+
aj.write_date
48+
FROM account_journal aj
49+
INNER JOIN res_company rc ON rc.id = aj.company_id
50+
WHERE aj.id in %s
51+
""", (tuple(journal_ids),))
52+
# We will add all options in order to ensure no failures
53+
openupgrade.logged_query(
54+
env.cr, """
55+
INSERT INTO pos_config_pos_payment_method_rel
56+
(pos_config_id, pos_payment_method_id)
57+
SELECT DISTINCT ps.config_id, ppm.id
58+
FROM account_bank_statement abs
59+
JOIN pos_payment_method ppm ON abs.journal_id = ppm.old_journal_id
60+
JOIN pos_session ps ON ps.id = abs.pos_session_id
61+
WHERE abs.pos_session_id IS NOT NULL
62+
""")
63+
env["pos.config"].generate_pos_journal()
64+
65+
66+
def create_pos_payments(env):
67+
env.cr.execute("""
68+
SELECT DISTINCT absl.id, ppm.id, absl.pos_statement_id,
69+
absl.name, absl.amount, absl.create_date
70+
FROM account_bank_statement abs
71+
JOIN pos_session ps ON abs.pos_session_id = ps.id
72+
JOIN account_bank_statement_line absl ON absl.statement_id = abs.id
73+
LEFT JOIN account_journal aj ON abs.journal_id = aj.id
74+
JOIN pos_payment_method ppm ON ppm.old_journal_id = aj.id
75+
WHERE absl.pos_statement_id IS NOT NULL
76+
""")
77+
st_lines = env.cr.fetchall()
78+
if st_lines:
79+
vals_list = []
80+
for st_line in st_lines:
81+
vals = {
82+
'name': st_line[3],
83+
'pos_order_id': st_line[2],
84+
'amount': st_line[4],
85+
'payment_method_id': st_line[1],
86+
'payment_date': st_line[5],
87+
}
88+
vals_list += [vals]
89+
env['pos.payment'].create(vals_list)
90+
# We need to delete all the lines from sessions not validated in order to not
91+
# disturb validation
92+
env.cr.execute("""
93+
SELECT absl.id
94+
FROM account_bank_statement abs
95+
JOIN pos_session ps ON abs.pos_session_id = ps.id
96+
JOIN account_bank_statement_line absl ON absl.statement_id = abs.id
97+
WHERE absl.pos_statement_id IS NOT NULL AND ps.state != 'closed'
98+
""")
99+
st = env.cr.fetchall()
100+
to_delete = [s[0] for s in st]
101+
if to_delete:
102+
openupgrade.logged_query(env.cr, """
103+
DELETE FROM account_bank_statement_line
104+
WHERE id in %s
105+
""", (tuple(to_delete),))
106+
env["account.bank.statement"].search(
107+
[("pos_session_id.state", "!=", "closed")]
108+
)._end_balance()
109+
110+
111+
def fill_stock_warehouse_pos_type_id(env):
112+
warehouses = env['stock.warehouse'].search([('pos_type_id', '=', False)])
113+
for warehouse in warehouses:
114+
if warehouse.get_external_id()[warehouse.id] == "stock.warehouse0":
115+
# If it's the main warehouse, assign the existing type
116+
warehouse.pos_type_id = env.ref("point_of_sale.picking_type_posout")
117+
continue
118+
color = warehouse.in_type_id.color
119+
sequence_data = warehouse._get_sequence_values()
120+
max_sequence = env['stock.picking.type'].search_read(
121+
[('sequence', '!=', False)], ['sequence'], limit=1,
122+
order='sequence desc')
123+
max_sequence = max_sequence and max_sequence[0]['sequence'] or 0
124+
create_data = warehouse._get_picking_type_create_values(max_sequence)[0]
125+
picking_type = "pos_type_id"
126+
sequence = env['ir.sequence'].sudo().create(sequence_data[picking_type])
127+
create_data[picking_type].update(
128+
warehouse_id=warehouse.id, color=color, sequence_id=sequence.id)
129+
warehouse[picking_type] = env['stock.picking.type'].create(
130+
create_data[picking_type]).id
131+
# Remove this to disappear XML-ID for avoiding error
132+
env["ir.model.data"].search([
133+
("module", "=", "point_of_sale"),
134+
("name", "=", "picking_type_posout"),
135+
]).unlink()
136+
137+
138+
def fix_pos_payment_method_config_relation(env):
139+
"""Inserting only the right elements"""
140+
openupgrade.logged_query(
141+
env.cr, """DELETE FROM pos_config_pos_payment_method_rel"""
142+
)
143+
openupgrade.logged_query(
144+
env.cr, """
145+
INSERT INTO pos_config_pos_payment_method_rel
146+
(pos_config_id, pos_payment_method_id)
147+
SELECT pos_config_id, ppm.id
148+
FROM pos_config_journal_rel pcjr
149+
JOIN pos_payment_method ppm ON pcjr.journal_id = ppm.old_journal_id
150+
""")
151+
152+
153+
@openupgrade.migrate()
154+
def migrate(env, version):
155+
create_pos_payment_methods(env)
156+
create_pos_payments(env)
157+
fix_pos_payment_method_config_relation(env)
158+
fill_stock_warehouse_pos_type_id(env)

addons/point_of_sale/migrations/13.0.1.0.1/noupdate_changes.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version='1.0' encoding='utf-8'?>
22
<odoo>
3-
<record id="pos_config_main" model="pos.config">
3+
<!-- <record id="pos_config_main" model="pos.config">
44
<field name="picking_type_id"/>
5-
</record>
5+
</record>-->
66
<record id="product_product_consumable" model="product.product">
77
<field name="default_code">DISC</field>
8-
<field name="image" type="base64" file="point_of_sale/static/img/product_product_49-image.jpg"/>
8+
<!-- <field name="image_1920" type="base64" file="point_of_sale/static/img/product_product_49-image.jpg"/>-->
99
<field name="list_price">0.00</field>
1010
<field name="name">Discount</field>
1111
<field name="standard_price">0.00</field>
1212
<field name="purchase_ok">False</field>
1313
<field name="weight">0.00</field>
1414
</record>
1515
<record id="product_product_tip" model="product.product">
16-
<field name="taxes_id" eval="[(5,)]"/>
16+
<!-- <field name="taxes_id" eval="[(5,)]"/>-->
1717
<field name="weight">0.01</field>
1818
</record>
1919
<record id="seq_pos_session" model="ir.sequence">
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---Models in module 'point_of_sale'---
2+
obsolete model pos.open.statement [transient]
3+
new model closing.balance.confirm.wizard [transient]
4+
# NOTHING TO DO
5+
6+
new model pos.payment
7+
new model pos.payment.method
8+
# DONE: created some records as explained below (created pos.payment record from statement lines)
9+
10+
---Fields in module 'point_of_sale'---
11+
point_of_sale / account.bank.statement.cashbox / is_a_template (boolean) : NEW hasdefault
12+
# NOTHING TO DO: has default
13+
14+
point_of_sale / account.cashbox.line / default_pos_id (many2one) : DEL relation: pos.config
15+
point_of_sale / pos.config / default_cashbox_id (many2one) : NEW relation: account.bank.statement.cashbox
16+
point_of_sale / pos.config / default_cashbox_lines_ids (one2many): DEL relation: account.cashbox.line
17+
point_of_sale / account.bank.statement.cashbox / pos_config_ids (one2many) : NEW relation: pos.config
18+
DONE: post-migration: filled default_cashbox_id using default_pos_id relation
19+
20+
point_of_sale / account.journal / amount_authorized_diff (float): DEL
21+
point_of_sale / pos.config / amount_authorized_diff (float): NEW
22+
# DONE: post-migration: mapping
23+
24+
point_of_sale / account.journal / journal_user (boolean) : DEL
25+
# NOTHING TO DO: old technical field used to mark which journals could be used in the pos config
26+
27+
point_of_sale / pos.order / invoice_id (many2one) : DEL relation: account.invoice
28+
point_of_sale / account.move / pos_order_ids (one2many) : NEW relation: pos.order
29+
# DONE: post-migration: assured the merge account.invoice -> account.move is handled correctly
30+
31+
point_of_sale / pos.category / image (binary) : DEL attachment: True
32+
point_of_sale / pos.category / image_128 (binary) : NEW attachment: True
33+
point_of_sale / pos.category / image_medium (binary) : DEL attachment: True
34+
point_of_sale / pos.category / image_small (binary) : DEL attachment: True
35+
# DONE: pre-migration (renamed)
36+
37+
point_of_sale / pos.config / barcode_nomenclature_id (many2one): now required, req_default: function
38+
# DONE: post-migration: filled empty cases
39+
40+
point_of_sale / pos.config / module_pos_hr (boolean) : NEW
41+
# DONE: post-migration: marked as True if hr is installed, because the new pos_hr module has auto_install = True
42+
43+
point_of_sale / pos.config / group_by (boolean) : DEL
44+
point_of_sale / pos.config / journal_ids (many2many) : DEL relation: account.journal
45+
point_of_sale / pos.config / payment_method_ids (many2many): NEW relation: pos.payment.method, hasdefault
46+
point_of_sale / account.journal / pos_payment_method_ids (one2many): NEW relation: pos.payment.method
47+
# DONE: end-migration: for each journal in journal_ids, created a pos.payment.method record with cash_journal_id pointing the corresponding journal
48+
49+
point_of_sale / pos.config / barcode_scanner (boolean) : DEL
50+
point_of_sale / pos.config / customer_facing_display_html (html): not stored anymore
51+
point_of_sale / pos.config / customer_facing_display_html (html): now a function
52+
point_of_sale / pos.config / iface_available_categ_ids (many2many): NEW relation: pos.category
53+
point_of_sale / pos.config / iface_payment_terminal (boolean): DEL
54+
point_of_sale / pos.config / limit_categories (boolean) : NEW
55+
point_of_sale / pos.config / other_devices (boolean) : NEW
56+
point_of_sale / pos.config / stock_location_id (many2one) : DEL relation: stock.location, required, req_default: function
57+
# NOTHING TO DO
58+
59+
point_of_sale / pos.order / payment_ids (one2many) : NEW relation: pos.payment
60+
point_of_sale / pos.order / statement_ids (one2many) : DEL relation: account.bank.statement.line
61+
# DONE: end-migration: for each statement line in statement_ids, created a pos.payment record with pos_order_id pointing the corresponding statement line
62+
63+
point_of_sale / pos.order / currency_rate (float) : previously in module pos_sale
64+
point_of_sale / pos.order / to_invoice (boolean) : NEW
65+
point_of_sale / pos.order.line / company_id (many2one) : now related
66+
# NOTHING TO DO
67+
68+
point_of_sale / pos.order.line / order_id (many2one) : now required
69+
# DONE: post-migration: deleted empty cases
70+
71+
point_of_sale / pos.payment / amount (float) : NEW required
72+
point_of_sale / pos.payment / card_type (char) : NEW
73+
point_of_sale / pos.payment / name (char) : NEW
74+
point_of_sale / pos.payment / payment_date (datetime) : NEW required, req_default: function, hasdefault
75+
point_of_sale / pos.payment / payment_method_id (many2one) : NEW relation: pos.payment.method, required
76+
point_of_sale / pos.payment / pos_order_id (many2one) : NEW relation: pos.order, required
77+
point_of_sale / pos.payment / session_id (many2one) : NEW relation: pos.session, isrelated: related, stored
78+
point_of_sale / pos.payment / transaction_id (char) : NEW
79+
point_of_sale / pos.payment.method / cash_journal_id (many2one) : NEW relation: account.journal
80+
point_of_sale / pos.payment.method / company_id (many2one) : NEW relation: res.company, hasdefault
81+
point_of_sale / pos.payment.method / config_ids (many2many) : NEW relation: pos.config
82+
point_of_sale / pos.payment.method / is_cash_count (boolean) : NEW
83+
point_of_sale / pos.payment.method / name (char) : NEW required
84+
point_of_sale / pos.payment.method / receivable_account_id (many2one): NEW relation: account.account, required, req_default: function, hasdefault
85+
point_of_sale / pos.payment.method / split_transactions (boolean) : NEW hasdefault
86+
point_of_sale / pos.payment.method / use_payment_terminal (selection): NEW selection_keys: function
87+
# NOTHING TO DO: new models
88+
89+
point_of_sale / pos.session / cash_register_balance_end (float): not related anymore
90+
point_of_sale / pos.session / cash_register_balance_end (float): now a function
91+
point_of_sale / pos.session / cash_register_difference (float): not related anymore
92+
point_of_sale / pos.session / cash_register_difference (float): now a function
93+
point_of_sale / pos.session / cash_register_total_entry_encoding (float): not related anymore
94+
point_of_sale / pos.session / cash_register_total_entry_encoding (float): now a function
95+
point_of_sale / pos.session / state (selection) : selection_keys is now '['closed', 'closing_control', 'new_session', 'opened', 'opening_control']' ('['closed', 'closing_control', 'opened', 'opening_control']')
96+
# NOTHING TO DO
97+
98+
point_of_sale / pos.session / activity_ids (one2many) : NEW relation: mail.activity
99+
point_of_sale / pos.session / message_follower_ids (one2many): NEW relation: mail.followers
100+
point_of_sale / pos.session / message_ids (one2many) : NEW relation: mail.message
101+
point_of_sale / pos.session / message_main_attachment_id (many2one): NEW relation: ir.attachment
102+
point_of_sale / pos.session / website_message_ids (one2many): NEW relation: mail.message
103+
# NOTHING TO DO: mail activity and mail thread fields
104+
105+
point_of_sale / pos.session / move_id (many2one) : NEW relation: account.move
106+
# DONE: post-migration: filled empty cases for closed sessions
107+
108+
point_of_sale / res.partner / barcode (char) : previously in module base
109+
point_of_sale / res.partner / pos_order_ids (one2many) : NEW relation: pos.order
110+
point_of_sale / res.users / pos_security_pin (char) : DEL
111+
# NOTHING TO DO
112+
113+
point_of_sale / stock.warehouse / pos_type_id (many2one) : NEW relation: stock.picking.type
114+
# DONE: post-migration: fill with _create_or_update_sequences_and_picking_types method
115+
116+
---XML records in module 'point_of_sale'---
117+
DEL account.journal: point_of_sale.pos_sale_journal (noupdate)
118+
# DONE: post-migration (removed)
119+
120+
NEW ir.actions.act_window: point_of_sale.action_payment_methods_tree
121+
NEW ir.actions.act_window: point_of_sale.action_pos_payment_form
122+
NEW ir.actions.act_window: point_of_sale.action_pos_payment_method_form
123+
DEL ir.actions.act_window: point_of_sale.account_journal_action_point_of_sale
124+
DEL ir.actions.act_window: point_of_sale.act_pos_config_sessions
125+
DEL ir.actions.act_window: point_of_sale.act_pos_open_statement
126+
DEL ir.actions.act_window: point_of_sale.act_pos_session_orders
127+
DEL ir.actions.act_window: point_of_sale.action_account_journal_form
128+
DEL ir.actions.act_window: point_of_sale.action_pos_box_in
129+
DEL ir.actions.act_window: point_of_sale.action_pos_open_statement
130+
# NOTHING TO DO: noupdate=0
131+
132+
DEL ir.actions.report: point_of_sale.action_report_account_statement [renamed to account module]
133+
# NOTHING TO DO: should be renamed in account migration, but don't needed (noupdate=0)
134+
135+
NEW ir.model.access: point_of_sale.access_decimal_precision_user
136+
NEW ir.model.access: point_of_sale.access_pos_payment_method_manager
137+
NEW ir.model.access: point_of_sale.access_pos_payment_method_user
138+
NEW ir.model.access: point_of_sale.access_pos_payment_user
139+
DEL ir.model.access: point_of_sale.access_product_price_history_pos_manager
140+
NEW ir.module.category: base.module_category_sales_point_of_sale (noupdate)
141+
NEW ir.rule: point_of_sale.rule_pos_payment_method_multi_company
142+
NEW ir.rule: point_of_sale.rule_pos_payment_multi_company
143+
# NOTHING TO DO
144+
145+
DEL ir.sequence: point_of_sale.seq_picking_type_posout (noupdate)
146+
# DONE: post-migration (removed)
147+
148+
NEW ir.ui.menu: point_of_sale.menu_pos_payment
149+
NEW ir.ui.menu: point_of_sale.menu_pos_payment_method
150+
DEL ir.ui.menu: point_of_sale.menu_action_account_journal_form_open
151+
DEL ir.ui.menu: point_of_sale.pos_menu_products_variants_action
152+
NEW ir.ui.view: point_of_sale.assets_tests
153+
NEW ir.ui.view: point_of_sale.closing_balance_confirm
154+
NEW ir.ui.view: point_of_sale.pos_payment_method_view_form
155+
NEW ir.ui.view: point_of_sale.pos_payment_method_view_search
156+
NEW ir.ui.view: point_of_sale.pos_payment_method_view_tree
157+
NEW ir.ui.view: point_of_sale.product_uom_categ_tree_view
158+
NEW ir.ui.view: point_of_sale.view_account_bnk_stmt_cashbox
159+
NEW ir.ui.view: point_of_sale.view_account_bnk_stmt_cashbox_footer
160+
NEW ir.ui.view: point_of_sale.view_bank_statement_pos_session
161+
NEW ir.ui.view: point_of_sale.view_pos_order_pivot
162+
NEW ir.ui.view: point_of_sale.view_pos_order_tree_no_session_id
163+
NEW ir.ui.view: point_of_sale.view_pos_payment_form
164+
NEW ir.ui.view: point_of_sale.view_pos_payment_search
165+
NEW ir.ui.view: point_of_sale.view_pos_payment_tree
166+
DEL ir.ui.view: point_of_sale.FieldTextHtml
167+
DEL ir.ui.view: point_of_sale.customer_facing_display_snippets
168+
DEL ir.ui.view: point_of_sale.extra_head
169+
DEL ir.ui.view: point_of_sale.pos_editor_assets
170+
DEL ir.ui.view: point_of_sale.pos_editor_fieldtexthtml_assets
171+
DEL ir.ui.view: point_of_sale.report_statement
172+
DEL ir.ui.view: point_of_sale.res_users_view_form
173+
DEL ir.ui.view: point_of_sale.view_account_bank_journal_form_inherited_pos
174+
DEL ir.ui.view: point_of_sale.view_account_journal_search_inherit_point_of_sale
175+
DEL ir.ui.view: point_of_sale.view_pos_open_statement
176+
NEW mail.activity.type: point_of_sale.mail_activity_old_session
177+
# NOTHING TO DO: noupdate=0
178+
179+
DEL stock.picking.type: point_of_sale.picking_type_posout
180+
# DONE: post-migration: Remove XML-ID, as the picking type may be in use

0 commit comments

Comments
 (0)