add channel as agent if it has commission pay in operation and sale

This commit is contained in:
wilson gomez 2021-05-20 16:16:25 -05:00
parent a0c1bfdc6e
commit 252aa23f12
4 changed files with 17 additions and 1 deletions

View File

@ -887,6 +887,7 @@ class BookingLine(ModelSQL, ModelView):
@classmethod
def create_operation(cls, party, line, accommodation, unit_price):
Operation = Pool().get('hotel.operation')
Agent = Pool().get('commission.agent')
kind = 'occupancy'
# if not accommodation:
@ -912,6 +913,12 @@ class BookingLine(ModelSQL, ModelView):
if line.main_guest:
values['main_guest'] = line.main_guest.id
if line.booking.party_seller:
party_seller = line.booking.party_seller.party.id_number
agents = Agent.search([('party.id_number', '=', party_seller)])
if agents:
values['agent'] = agents[0]
operation, = Operation.create([values])
line.write([line], {'operation': operation.id})

View File

@ -133,6 +133,7 @@ class Operation(Workflow, ModelSQL, ModelView):
'operation_target', 'Transfered Operations', states=STATES_OP)
vouchers = fields.Many2Many('hotel.operation-account.voucher', 'operation',
'voucher', 'Vouchers', states=STATES_OP, domain=[], depends=['party'])
agent = fields.Many2One('commission.agent', 'Agent')
# stock_moves = fields.Many2Many('hotel.operation-stock.move', 'operation',
# 'move', 'Stock Moves', states={'readonly': True})
@ -570,6 +571,7 @@ class Operation(Workflow, ModelSQL, ModelView):
'payment_term': None,
'guests_qty': len(op.guests) + 1,
'reference': op.reference,
'agent': op.agent or None,
'rooms': op.room.name,
'company': op.company.id,
'add_default_charges': op.add_default_charges,
@ -642,7 +644,6 @@ class Operation(Workflow, ModelSQL, ModelView):
ctx['currency'] = rec['currency']
if rec.party:
ctx['customer'] = rec.party.id
sale = cls._get_new_sale(rec)
sale.save()
if rec.get('vouchers'):
@ -688,6 +689,7 @@ class Operation(Workflow, ModelSQL, ModelView):
pool = Pool()
Sale = pool.get('sale.sale')
Party = pool.get('party.party')
Agent = pool.get('commission.agent')
Date = pool.get('ir.date')
date_ = Date.today()
@ -699,6 +701,9 @@ class Operation(Workflow, ModelSQL, ModelView):
party = Party(data['party'])
description = data.get('rooms')
reference = data.get('reference')
agent = None
if data.get('agent'):
agent = Agent(data['agent'])
return Sale(
company=company_id,
@ -709,6 +714,7 @@ class Operation(Workflow, ModelSQL, ModelView):
description=description,
state='draft',
reference=reference,
agent=agent,
invoice_address=Party.address_get(party, type='invoice'),
shipment_address=Party.address_get(party, type='delivery'),
)

View File

@ -12,6 +12,7 @@ depends:
party_personal
company_timezone
email
commission
xml:
hotel.xml
configuration.xml

View File

@ -48,6 +48,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="origin"/>
<label name="sale_line"/>
<field name="sale_line"/>
<label name="agent"/>
<field name="agent"/>
<separator name="notes" colspan="4"/>
<field name="notes" colspan="4"/>
</page>