Last active
February 7, 2020 15:27
-
-
Save jev-odoo/96307b13cc97b363639a82be1c88e53e to your computer and use it in GitHub Desktop.
POS - Fix Reconcile Stock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SESSION_IDS = [<<SESSION_IDS>>] | |
| db_version = 0 | |
| latest_version = env['ir.module.module'].search([('name', '=', 'base')]).latest_version.replace('~', '-') | |
| for version in (10, 11, 12, 13): | |
| if latest_version.startswith(str(version)) or latest_version.startswith('saas-%s' % str(version)): | |
| db_version = version | |
| def fix_reconcile_stock(sessions): | |
| for session in sessions: | |
| aml_to_unreconcile = env['account.move.line'] | |
| invoiced_orders = session.mapped('order_ids').filtered(lambda x: x.is_invoiced) | |
| rec_move_lines = invoiced_orders.mapped('account_move.line_ids').filtered(lambda x: x.account_id.internal_type == 'receivable' and x.reconciled) | |
| if rec_move_lines: | |
| aml_to_unreconcile |= rec_move_lines | |
| stock_moves = env['stock.move'].search([('picking_id', 'in', session.order_ids.filtered(lambda order: not order.is_invoiced).mapped('picking_id').ids)]) | |
| rec_move_lines = env['account.move'].search([('stock_move_id', 'in', stock_moves.ids)]).mapped('line_ids').filtered(lambda x: x.reconciled) | |
| if rec_move_lines: | |
| aml_to_unreconcile |= rec_move_lines | |
| if aml_to_unreconcile: | |
| aml_to_unreconcile.remove_move_reconcile() | |
| domain = [('id', 'in', SESSION_IDS)] | |
| sessions = env['pos.session'].sudo().search(domain) | |
| fix_reconcile_stock(sessions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment