59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
import sys
|
|
|
|
def clone_payment_methods(env):
|
|
source_name = 'Kedai Kipas 58 Rungkut'
|
|
target_name = 'Kedai Kipas 58 Tenggilis'
|
|
|
|
# Using 'ilike' to be safe with exact naming
|
|
source_company = env['res.company'].search([('name', 'ilike', source_name)], limit=1)
|
|
target_company = env['res.company'].search([('name', 'ilike', target_name)], limit=1)
|
|
|
|
if not source_company or not target_company:
|
|
print(f"Could not find one or both companies: '{source_name}', '{target_name}'")
|
|
return
|
|
|
|
print(f"Source: {source_company.name} (ID: {source_company.id})")
|
|
print(f"Target: {target_company.name} (ID: {target_company.id})")
|
|
|
|
# Fetch all payment methods from the source company
|
|
methods = env['pos.payment.method'].with_context(active_test=False).search([
|
|
('company_id', '=', source_company.id)
|
|
])
|
|
|
|
print(f"Found {len(methods)} payment methods in {source_company.name} to clone.")
|
|
|
|
count = 0
|
|
for method in methods:
|
|
# Check if a method with the same name already exists in target to avoid duplicates
|
|
existing = env['pos.payment.method'].with_context(active_test=False).search([
|
|
('name', '=', method.name),
|
|
('company_id', '=', target_company.id)
|
|
], limit=1)
|
|
|
|
if existing:
|
|
print(f" -> '{method.name}' already exists in {target_company.name}. Skipping.")
|
|
continue
|
|
|
|
# Clone the method and assign to target company
|
|
# the .copy() method will duplicate the record. We just override company_id.
|
|
# Ensure we pass the explicit account mappings to avoid Odoo triggering a duplicate account creation
|
|
new_method = method.copy({
|
|
'company_id': target_company.id,
|
|
'receivable_account_id': method.receivable_account_id.id if method.receivable_account_id else False,
|
|
'outstanding_account_id': method.outstanding_account_id.id if method.outstanding_account_id else False,
|
|
'journal_id': method.journal_id.id if method.journal_id else False,
|
|
})
|
|
print(f" -> Cloned '{method.name}' (New ID: {new_method.id})")
|
|
count += 1
|
|
|
|
print(f"Committing changes... (Cloned {count} methods)")
|
|
env.cr.commit()
|
|
print("Cloning complete!")
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
clone_payment_methods(env)
|
|
except NameError:
|
|
print("Please run this script using Odoo shell:")
|
|
print("Example: ./.venv/bin/python ./odoo/odoo-bin shell -d <DB_NAME> -c odoo.conf < scripts/clone_pos_payment_methods.py")
|