Skip to Content
Menu
This question has been flagged
2365 Views

i noticed that in odoo 10 the account invoice module has 2 methods (pay_and_reconcile() and action_invoice_paid()) to reconcile and change the state of the invoice from open to paid i wanted to use those methods to make the invoice auto reconcile with the pos order. how can i do that? 

i was trying to find a way to call this 2 methods in create_from_ui() from pos_order but i think im not doing it the right way.

can you try to explain me this problem please


Avatar
Discard
Author

i already solved my problem i just had to add a few lines

inside the method create_from_ui() that is in the class pos_order , inside the if .

@api.model

def create_from_ui(self, orders):

# Keep only new orders

submitted_references = [o['data']['name'] for o in orders]

pos_order = self.search([('pos_reference', 'in', submitted_references)])

existing_orders = pos_order.read(['pos_reference'])

existing_references = set([o['pos_reference'] for o in existing_orders])

orders_to_save = [o for o in orders if o['data']['name'] not in existing_references]

order_ids = []

for tmp_order in orders_to_save:

to_invoice = tmp_order['to_invoice']

order = tmp_order['data']

if to_invoice:

self._match_payment_to_invoice(order)

pos_order = self._process_order(order)

order_ids.append(pos_order.id)

try:

pos_order.action_pos_order_paid()

except psycopg2.OperationalError:

# do not hide transactional errors, the order(s) won't be saved!

raise

except Exception as e:

_logger.error('Could not fully process the POS Order: %s', tools.ustr(e))

if to_invoice:

pos_order.action_pos_order_invoice()

pos_order.invoice_id.sudo().action_invoice_open()

pos_order.account_move = pos_order.invoice_id.move_id

#Edited by me-----------------------------------------------

for statement in pos_order.statement_ids:

pos_order.invoice_id.sudo().pay_and_reconcile(statement.journal_id)

pos_order.invoice_id.sudo().action_invoice_paid()

#----------------------------------------------------

return order_ids