This question has been flagged

I am trying to set the order date from the POS order(pos.order) as the date in invoice(account.invoice). I've tried to super action_pos_order_invoice with the date field from the order based on the code (shown as commented), and I'm getting the error


AttributeError: 'dict' object has no attribute 'order'

What am I doing wrong here?




@ api.multi 
def action_pos_order_invoice (self):
invoice_fields = super (PosOrder, self) .action_pos_order_invoice ()
Invoice = self.env ['account.invoice']
for order in self:
# invoice.fiscal_position_id = order.fiscal_position_id (path:/addons/point_of_sale/models/pos_orders.py/ line: 687)
invoice = Invoice.new (order._prepare_invoice ())
print (invoice_fields.order.date_order)
invoice.date_invoice = invoice_fields.order.date_order

return invoice_fields
Avatar
Discard
Best Answer

Hi,

Just use the following code for your purpose. just re-write the function in model pos.order


def _prepare_invoice(self):
"""
Prepare the dict of values to create the new invoice for a pos order.
"""
invoice_type = 'out_invoice' if self.amount_total >= 0 else 'out_refund'
return {
'name': self.name,
'origin': self.name,
'account_id': self.partner_id.property_account_receivable_id.id,
'journal_id': self.session_id.config_id.invoice_journal_id.id,
'company_id': self.company_id.id,
'type': invoice_type,
'reference': self.name,
'date_invoice': self.date_order.date(),
'partner_id': self.partner_id.id,
'comment': self.note or '',
# considering partner's sale pricelist's currency
'currency_id': self.pricelist_id.currency_id.id,
'user_id': self.user_id.id,
}
Avatar
Discard
Author

I supered that function and got the desired output. Thank you so much for the help.

Code I used:

def _prepare_invoice(self):

invoice_fields = super(PosOrder, self)._prepare_invoice()

invoice_fields['date_invoice'] = self['date_order'].date()

return invoice_fields

Yes this one is the better solution( Super the function)