Debian Codegraph @

addons/l10n_tw_edi_ecpay/wizard/l10n_tw_edi_invoice_print.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import models, fields
4 from odoo.addons.l10n_tw_edi_ecpay.utils import call_ecpay_api, convert_utc_time_to_tw_time
5 from odoo.exceptions import UserError
6
7
8 class L10nTwEDIInvoicePrint(models.TransientModel):
9 _name = "l10n_tw_edi.invoice.print"
10 _description = "Implements printingan ecpay invoice."
11
12 invoice_id = fields.Many2one(
13 comodel_name="account.move",
14 string="Document To Print",
15 required=True,
16 readonly=True,
17 )
18 print_format_b2c = fields.Selection(
19 string="Print Format (B2C)",
20 selection=[
21 ("1", "single-sided printing"),
22 ("2", "double-sided printing"),
23 ("3", "printing with thermal paper"),
24 ],
25 default="1",
26 )
27 print_format_b2b = fields.Selection(
28 string="Print Format (B2B)",
29 selection=[
30 ("1", "A4 printing "),
31 ("2", "A5 printing "),
32 ],
33 default="1",
34 )
35 l10n_tw_edi_is_b2b = fields.Boolean(string="Is B2B", related="invoice_id.l10n_tw_edi_is_b2b")
36
37 def button_print(self):
38 self.ensure_one()
39
40 json_data = {
41 "MerchantID": self.invoice_id.company_id.sudo().l10n_tw_edi_ecpay_merchant_id,
42 "InvoiceNo": self.invoice_id.l10n_tw_edi_ecpay_invoice_id,
43 "InvoiceDate": convert_utc_time_to_tw_time(self.invoice_id.l10n_tw_edi_invoice_create_date),
44 "PrintStyle": self.print_format_b2b if self.l10n_tw_edi_is_b2b else self.print_format_b2c,
45 "IsShowingDetail": "1",
46 }
47
48 response_data = call_ecpay_api("/InvoicePrint", json_data, self.invoice_id.company_id, self.l10n_tw_edi_is_b2b)
49 if response_data.get('RtnCode') != 1:
50 raise UserError(self.env._("Error: %(error)s", error=response_data.get('RtnMsg')))
51
52 return {
53 'type': 'ir.actions.act_url',
54 'target': 'new',
55 'url': response_data.get("InvoiceHtml"),
56 }