[FIX] Send partner_bank_id at the end of PoS session for swiss QR_Bill
Users with Swiss localization have a possibility to create QR_Bills from their invoices, however, PoS currently does not send information about partner_bank_id to the generated invoice, so users can not create QR_Bill from the invoice that was created by PoS. After this commit, function _get_partner_bank_id will get partner_bank_id in case customer didn't pay for the order fully, and this information will be added to the invoice, thus, giving user an ability to create a QR-Bill from said invoice. In case user will try to create a QR-Bill from the invoice that has been fully paid, they will get an error saying that QR-Bill can not be generated on paid invoices. If the user tries to generate QR-Bill from the invoice that has empty partner_bank_id, they will also get an error notifying them that they should check Recipient Bank field on the invoice. OPW-2695969 closes odoo/odoo#83456 X-original-commit: 634f90a728cba9ff45c17e471f2b160e939bbd3d Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
@@ -298,6 +298,9 @@ class AccountMove(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
if not self.partner_bank_id:
|
||||
raise UserError(_("QR-Bill can not be generated on paid invoices. If the invoice is not fully paid, please make sure Recipient Bank field is not empty and try again."))
|
||||
|
||||
if not self.partner_bank_id._eligible_for_qr_code('ch_qr', self.partner_id, self.currency_id):
|
||||
raise UserError(_("Cannot generate the QR-bill. Please check you have configured the address of your company and debtor. If you are using a QR-IBAN, also check the invoice's payment reference is a QR reference."))
|
||||
|
||||
|
||||
@@ -480,6 +480,16 @@ class PosOrder(models.Model):
|
||||
currency = self.currency_id
|
||||
return currency.round(amount) if currency else amount
|
||||
|
||||
def _get_partner_bank_id(self):
|
||||
bank_partner_id = False
|
||||
has_pay_later = any(not pm.journal_id for pm in self.payment_ids.mapped('payment_method_id'))
|
||||
if has_pay_later:
|
||||
if self.amount_total <= 0 and self.partner_id.bank_ids:
|
||||
bank_partner_id = self.partner_id.bank_ids[0].id
|
||||
elif self.amount_total >= 0 and self.company_id.partner_id.bank_ids:
|
||||
bank_partner_id = self.company_id.partner_id.bank_ids[0].id
|
||||
return bank_partner_id
|
||||
|
||||
def _create_invoice(self, move_vals):
|
||||
self.ensure_one()
|
||||
new_move = self.env['account.move'].sudo().with_company(self.company_id).with_context(default_move_type=move_vals['move_type']).create(move_vals)
|
||||
@@ -586,6 +596,7 @@ class PosOrder(models.Model):
|
||||
'move_type': 'out_invoice' if self.amount_total >= 0 else 'out_refund',
|
||||
'ref': self.name,
|
||||
'partner_id': self.partner_id.id,
|
||||
'partner_bank_id': self._get_partner_bank_id(),
|
||||
# considering partner's sale pricelist's currency
|
||||
'currency_id': self.pricelist_id.currency_id.id,
|
||||
'invoice_user_id': self.user_id.id,
|
||||
|
||||
Reference in New Issue
Block a user