#!/usr/bin/python
# -*- coding: utf-8 -*-
import base64
# from base64 import b64encode
from odoo import models, fields, api, _
from odoo.exceptions import UserError, Warning
def generate_tlv_hex(*args):
"""to combine all tags with conversion to hex decimal"""
b_array = bytearray()
for index, val in enumerate(args):
b_array.append(index + 1)
b_array.append(len(val))
b_array.extend(val.encode('utf-8'))
return b_array
def generate_tlv_base64(*args):
tlv_hex = generate_tlv_hex(args) # true
return str(base64.b64encode(tlv_hex), "utf-8")
class AccountMove(models.Model):
_name = "account.move"
_inherit = "account.move"
einv_amount_sale_total = fields.Monetary(string="Amount sale total", compute="_compute_total", store='True',
help="")
einv_amount_discount_total = fields.Monetary(string="Amount discount total", compute="_compute_total", store='True',
help="")
einv_amount_tax_total = fields.Monetary(string="Amount tax total", compute="_compute_total", store='True', help="")
# einv_qr = fields.Char(string="Amount tax total", compute="_compute_total", store='True', help="", readonly=True)
# region odoo standard -------------------------
einv_sa_delivery_date = fields.Date(string='Delivery Date', default=fields.Date.context_today, copy=False)
einv_sa_show_delivery_date = fields.Boolean(compute='_compute_einv_show_delivery_date')
einv_sa_qr_code_str = fields.Char(string='Zatka QR Code', compute='_compute_eniv_qr_code_str')
einv_sa_confirmation_datetime = fields.Datetime(string='Confirmation Date', readonly=True, copy=False)
einv_sa_confirmed = fields.Boolean(compute='_compute_einv_sa_confirmation_datetime', store=True)
def _compute_einv_sa_confirmation_datetime(self):
for move in self:
move.einv_sa_confirmed = False
if not move.einv_sa_confirmation_datetime and move.state == 'posted' \
and move.move_type in ('out_invoice', 'out_refund'):
move.einv_sa_confirmed = True
move.einv_sa_confirmation_datetime = move.create_date
@api.depends('country_code', 'move_type')
def _compute_einv_show_delivery_date(self):
for move in self:
# move.einv_sa_show_delivery_date = False
move.einv_sa_show_delivery_date = move.country_code == 'SA' and move.move_type in (
'out_invoice', 'out_refund')
@api.depends('amount_total', 'amount_untaxed', 'einv_sa_confirmation_datetime', 'company_id', 'company_id.vat')
def _compute_eniv_qr_code_str(self):
""" Generate the qr code for Saudi e-invoicing. Specs are available at the following link at page 23
https://zatca.gov.sa/ar/E-Invoicing/SystemsDevelopers/Documents/20210528_ZATCA_Electronic_Invoice_Security_Features_Implementation_Standards_vShared.pdf
https://zatca.gov.sa/ar/E-Invoicing/SystemsDevelopers/Documents/QRCodeCreation.pdf
"""
def get_qr_encoding(tag, field):
company_name_byte_array = field.encode('UTF-8')
company_name_tag_encoding = tag.to_bytes(length=1, byteorder='big')
company_name_length_encoding = len(company_name_byte_array).to_bytes(length=1, byteorder='big')
return company_name_tag_encoding + company_name_length_encoding + company_name_byte_array
for record in self:
qr_code_str = ''
if record.einv_sa_confirmation_datetime and record.company_id.vat:
seller_name_enc = get_qr_encoding(1, record.company_id.display_name)
company_vat_enc = get_qr_encoding(2, record.company_id.vat)
time_sa = fields.Datetime.context_timestamp(self.with_context(tz='Asia/Riyadh'),
record.einv_sa_confirmation_datetime)
timestamp_enc = get_qr_encoding(3, time_sa.isoformat())
invoice_total_enc = get_qr_encoding(4, str(record.amount_total))
total_vat_enc = get_qr_encoding(5, str(record.currency_id.round(
record.amount_total - record.amount_untaxed)))
str_to_encode = seller_name_enc + company_vat_enc + timestamp_enc + invoice_total_enc + total_vat_enc
qr_code_str = base64.b64encode(str_to_encode).decode('UTF-8')
record.einv_sa_qr_code_str = qr_code_str
def _post(self, soft=True):
res = super()._post(soft)
for record in self:
if record.country_code == 'SA' and record.move_type in ('out_invoice', 'out_refund'):
if not record.einv_sa_show_delivery_date:
raise UserError(_('Delivery Date cannot be empty'))
if record.einv_sa_delivery_date < record.invoice_date:
raise UserError(_('Delivery Date cannot be before Invoice Date'))
self.write({
'einv_sa_confirmation_datetime': fields.Datetime.now()
})
return res
# endregion
@api.depends('invoice_line_ids', 'amount_total')
def _compute_total(self):
for r in self:
r.einv_amount_sale_total = r.amount_untaxed + sum(line.einv_amount_discount for line in r.invoice_line_ids)
r.einv_amount_discount_total = sum(line.einv_amount_discount for line in r.invoice_line_ids)
r.einv_amount_tax_total = sum(line.einv_amount_tax for line in r.invoice_line_ids)
# tags = seller_name, vat_no, inv_date, total, vat
# r.einv_qr = generate_tlv_base64(r.company_id.name, r.company_id.vat, r.invoice_date, r.amount_total, )
class AccountMoveLine(models.Model):
_name = "account.move.line"
_inherit = "account.move.line"
einv_amount_discount = fields.Monetary(string="Amount discount", compute="_compute_amount_discount", store='True',
help="")
einv_amount_tax = fields.Monetary(string="Amount tax", compute="_compute_amount_tax", store='True', help="")
@api.depends('discount', 'quantity', 'price_unit')
def _compute_amount_discount(self):
for r in self:
r.einv_amount_discount = r.quantity * r.price_unit * (r.discount / 100)
@api.depends('tax_ids', 'discount', 'quantity', 'price_unit')
def _compute_amount_tax(self):
for r in self:
r.einv_amount_tax = sum(r.price_subtotal * (tax.amount / 100) for tax in r.tax_ids)
没有合适的资源?快使用搜索试试~ 我知道了~
odoo16-电子发票
共32个文件
png:12个
py:7个
xml:5个
需积分: 0 25 下载量 80 浏览量
2023-05-10
17:32:31
上传
评论 3
收藏 7.84MB ZIP 举报
温馨提示
Odoo 16是一款开源的企业管理软件,具有强大的功能和可定制性。其中,电子发票是其财务管理模块中的一个重要功能,可以帮助企业快速、准确地管理发票,并提高财务流程的效率。 一、电子发票简介 电子发票是指将发票信息电子化,以电子数据形式传输、处理、存储和展示的发票形式。相较于传统的纸质发票,电子发票具有环保、方便、快捷、安全等诸多优点,受到越来越多企业的青睐。 二、Odoo 16电子发票功能 Odoo 16电子发票功能支持创建、管理和查询电子发票,包括增值税发票、普通发票、收据等各类发票。用户可以通过Odoo 16系统在发票管理页面创建、导入或扫描发票信息,同时可以将其与客户、供应商等相关联,并支持对发票进行编辑、审核、作废、退货等操作。 三、电子发票优势 1.减少人工操作:通过Odoo 16电子发票功能,企业可以快速、准确地管理发票信息,大大减少了人工操作的时间和错误率。 2.提高工作效率:Odoo 16电子发票功能的自动化处理功能,可以实现发票的自动匹配、自动开票等操作,提高工作效率和准确度。 3.环保节能:电子发票不需要印刷、存储等传统的纸质发票过程,有利于环保节能,符合国家
资源推荐
资源详情
资源评论
收起资源包目录
odoo16-电子发票.zip (32个子文件)
einv_sa
__init__.py 37B
__manifest__.py 2KB
report
base_document_layout.xml 3KB
account_move.xml 13KB
view
partner.xml 3KB
account_move_views.xml 720B
menu.xml 339B
model
__init__.py 124B
partner.py 578B
company.py 695B
base_document_layout.py 939B
account_move.py 6KB
static
css
report_style.css 1KB
description
assets
ghits_labtop1.jpg 201KB
qr1.png 124KB
main_screenshot.png 344KB
ghits_inv_apply.png 74KB
ghits_terms.svg 11KB
ghits_partner_info.png 19KB
ghits_fatora.png 194KB
qr.png 92KB
ghits_desktop_inv.jpg 100KB
ghits_bg.svg 1KB
ghits_inv_print.png 67KB
main_screenshot_pos.gif 5.84MB
cr_2021.png 79KB
ghits_menu.png 41KB
qr2.png 49KB
icon.png 27KB
main_screenshot.gif 783KB
index.html 20KB
icon.png 27KB
共 32 条
- 1
资源评论
odoo-特斯拉
- 粉丝: 117
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- YOLOV4-TINY权重文件
- 以下是一个使用贪心算法解决多机调度问题的基本步骤0.txt
- 基于大数据的房产估价是近年来随着技术的发展而兴起的一种新型估价方法.txt
- 企业供应链管理系统v3.rar
- 富芮坤FR8016HA蓝牙开发板使用手册+硬件PCB图+封装库+DEMO演示软件源代码.zip
- 基于YOLOv7的芯片表面缺陷检测系统
- 京东物流 数字化供应链综合研究报告2018.rar
- 基于YOLOv7的植物虫害识别&防治系统
- 2000.1-2023.8中国经济政策不确定性指数月度数据.xlsx
- Screenshot_2024-04-21-20-42-15-443_com.tencent.mm.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功