54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Test script: Verify aggregation to 2 lines on branch side.
|
|
"""
|
|
from datetime import datetime
|
|
|
|
COMPANY_NAME = "Mie Mapan Rungkut Mapan"
|
|
POS_CONFIG_NAME = "POS Rungkut"
|
|
|
|
company = env['res.company'].search([('name', '=', COMPANY_NAME)], limit=1)
|
|
pos_config = env['pos.config'].search([('name', '=', POS_CONFIG_NAME), ('company_id', '=', company.id)], limit=1)
|
|
|
|
# Get BCA and BTN
|
|
bca_pm = pos_config.payment_method_ids.filtered(lambda pm: pm.name == 'BCA')
|
|
btn_pm = pos_config.payment_method_ids.filtered(lambda pm: pm.name == 'BTN')
|
|
|
|
# Create session
|
|
session = env['pos.session'].with_company(company).create({
|
|
'user_id': env.uid,
|
|
'config_id': pos_config.id,
|
|
})
|
|
session.sudo().set_opening_control(0, None)
|
|
|
|
# Create 2 orders
|
|
product = env['product.product'].search([('available_in_pos', '=', True)], limit=1)
|
|
for pm, amount in [(bca_pm, 10000), (btn_pm, 20000)]:
|
|
order = env['pos.order'].create({
|
|
'company_id': company.id,
|
|
'session_id': session.id,
|
|
'pos_reference': f'TEST/{session.id}/{pm.name}',
|
|
'date_order': datetime.now(),
|
|
'amount_tax': 0, 'amount_total': amount, 'amount_paid': amount, 'amount_return': 0,
|
|
'lines': [(0, 0, {'product_id': product.id, 'qty': 1, 'price_unit': amount, 'price_subtotal': amount, 'price_subtotal_incl': amount})],
|
|
})
|
|
env['pos.payment'].create({
|
|
'pos_order_id': order.id, 'payment_method_id': pm.id, 'amount': amount, 'payment_date': datetime.now(),
|
|
})
|
|
order.action_pos_order_paid()
|
|
|
|
# Close session
|
|
session.sudo().action_pos_session_closing_control()
|
|
|
|
# Verify related moves
|
|
related_moves = session._get_related_account_moves()
|
|
clearing_move = related_moves.filtered(lambda m: m.ref == f"Inter-company clearing for {session.name}")
|
|
|
|
print(f"Session: {session.name}")
|
|
print(f"Clearing Move: {clearing_move.name}")
|
|
print(f"Number of lines in clearing move: {len(clearing_move.line_ids)}")
|
|
for line in clearing_move.line_ids:
|
|
print(f" {line.account_id.code} {line.name}: {line.debit or -line.credit}")
|
|
|
|
env.cr.rollback()
|