UBL Integration

develop
Andreas Osim 2025-02-25 11:11:09 +01:00
parent 48242b5dbb
commit 0a200c2288
4 changed files with 134 additions and 83 deletions

View File

@ -87,6 +87,8 @@ class AccountInvoice(models.Model):
default=lambda self: self.env.user if self.env.user.editor_name else '',
domain=[('editor_name', '!=', '')],track_visibility='onchange')
sent_by_mail = fields.Boolean(string='Per EMail versandt',track_visibility='onchange')
@api.multi
@api.onchange('partner_shipping_id')
@ -207,3 +209,21 @@ class AccountInvoice(models.Model):
action['context'] = str({"default_info": info, "invoice_ids": self.env.context.get("active_ids")})
return action
return self.env.ref('dp_reports_account.account_invoices_with_intrastat_short').report_action(self)
class MailComposeMessage(models.TransientModel):
_inherit = 'mail.compose.message'
@api.multi
def send_mail(self, auto_commit=False):
context = self._context
dm=context.get('default_model')
dri=context.get('default_res_id')
mis=context.get('mark_invoice_as_sent')
if dm == 'account.invoice' and \
dri and mis:
invoice = self.env['account.invoice'].browse(context['default_res_id'])
if not invoice.sent:
invoice.sent = True
invoice.sent_by_mail = True
self = self.with_context(mail_post_autofollow=True)
return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)

View File

@ -120,6 +120,9 @@ class MailTemplate(models.Model):
if template.report_template:
for res_id in template_res_ids:
attachments = []
res_partner = self.env['res.partner'].browse(values.get('partner_ids'))
report_name = self.render_template(template.report_name, template.model, res_id)
report = template.report_template
report_service = report.report_name
@ -137,7 +140,6 @@ class MailTemplate(models.Model):
for i in range(0, a):
output.addPage(input.getPage(i))
passphrase = str(values.get('partner_ids'))+"!"
Model = self.env[self.model]
@ -177,5 +179,29 @@ class MailTemplate(models.Model):
attachments.append((report_name, result))
results[res_id]['attachments'] = attachments
if not self.env.context.get('attach_ubl_xml_file'):
return results
for res_id, template in self.get_email_template(res_ids).items():
invoice = self.env['account.invoice'].browse(res_id)
version = invoice.get_ubl_version()
ubl_filename = invoice.get_ubl_filename(version=version)
ubl_attachments = self.env['ir.attachment'].search([
('res_model', '=', 'account.invoice'),
('res_id', '=', res_id),
('datas_fname', '=', ubl_filename)
], order='create_date desc', limit=1)
if not ubl_attachments:
ubl_attachments = invoice._generate_email_ubl_attachment()
if len(ubl_attachments) == 1 and template.report_name:
report_name = self.render_template(
template.report_name, template.model, res_id)
ext = '.xml'
if not report_name.endswith(ext):
report_name += ext
attachments = [(report_name, ubl_attachments.datas)]
else:
attachments = [(a.name, a.datas) for a in ubl_attachments]
results[res_id]['attachments'] += attachments
return multi_mode and results or results[res_ids[0]]

View File

@ -31,88 +31,6 @@ from odoo.tools import drop_view_if_exists
from dateutil.relativedelta import relativedelta
import dateutil.parser
class SaleCart(models.Model):
_name = 'sale.cart'
_auto = False
ASSEMBLY_STATES = [('import', 'Imported'),
('import_failed', 'Error Import'),
('created', 'Not Released'),
('approved', 'Released for Production'),
('wait', 'Released'),
('failed', 'Error Release'),
('started', 'Production Started'),
('done', 'Production Finished'),
('packed', 'Packed'),
('delivered', 'Delivered'),
('completed', 'Completed')]
order_states = [
('draft', 'Quotation'),
('sent', 'Quotation Sent'),
('sale', 'Sales Order'),
('done', 'Done'),
('cancel', 'Cancelled')]
order_id = fields.Many2one('sale.order', string = 'Quotation / Order')
origin = fields.Char(string='Shopping Cart')
client_order_ref = fields.Char(string='Customer Reference')
name = fields.Char(string='Quotation')
date_order = fields.Date(string='Quotation Date:')
create_date = fields.Datetime(string='Create Date:')
partner_id = fields.Many2one('res.partner', string = 'Customer')
company_id = fields.Many2one('res.company', string = 'Company')
user_id = fields.Many2one('res.users', string = 'User')
assembly_state = fields.Selection(ASSEMBLY_STATES, string="State PG")
state = fields.Selection(order_states, string="State")
in_company = fields.Boolean(default=False,compute='_in_company',store=False)
number_of_parts = fields.Integer(string='Anzahl Teile')
number_of_parts_open = fields.Integer(string='Teile offen')
number_of_fittings = fields.Integer(string='Anzahl Beschläge')
number_of_fittings_open = fields.Integer(string='Beschläge offen')
@api.multi
def _in_company(self):
sCompany = self.env.user.company_id
for record in self:
if record.company_id == sCompany:
record.in_company = True
@api.model_cr
def init(self):
# print("connected")
drop_view_if_exists(self._cr, 'sale_cart')
self._cr.execute("""CREATE OR REPLACE VIEW sale_cart AS
SELECT so.id AS id,
so.id AS order_id,
so.name AS name,
so.origin AS origin,
so.client_order_ref AS client_order_ref,
so.date_order AS date_order,
so.create_date AS create_date,
so.assembly_state AS assembly_state,
so.state AS state,
so.number_of_parts AS number_of_parts,
so.number_of_parts_open AS number_of_parts_open,
so.number_of_fittings AS number_of_fittings,
so.number_of_fittings_open AS number_of_fittings_open,
so.partner_id AS partner_id,
so.company_id AS company_id,
c_u.user_id AS user_id
FROM sale_order so
INNER JOIN res_company_users_rel c_u ON so.company_id = c_u.cid
WHERE so.state != 'cancel' AND so.origin != '' order by date_order desc
""")
@api.multi
def switch_company(self):
values = {'company_id': self.company_id.id}
self.env.user.write(values)
return {
'type': 'ir.actions.client',
'tag': 'reload_context',
}
class SaleOrder(models.Model):
_name = 'sale.order'
_inherit = ['sale.order', 'dp_custom.helper']
@ -1056,3 +974,86 @@ class SaleOrderLine(models.Model):
new_list_price, pricelist_id.currency_id)
discount = (new_list_price - price) / new_list_price * 100
return discount
class SaleCart(models.Model):
_name = 'sale.cart'
_auto = False
ASSEMBLY_STATES = [('import', 'Imported'),
('import_failed', 'Error Import'),
('created', 'Not Released'),
('approved', 'Released for Production'),
('wait', 'Released'),
('failed', 'Error Release'),
('started', 'Production Started'),
('done', 'Production Finished'),
('packed', 'Packed'),
('delivered', 'Delivered'),
('completed', 'Completed')]
order_states = [
('draft', 'Quotation'),
('sent', 'Quotation Sent'),
('sale', 'Sales Order'),
('done', 'Done'),
('cancel', 'Cancelled')]
order_id = fields.Many2one('sale.order', string = 'Quotation / Order')
origin = fields.Char(string='Shopping Cart')
client_order_ref = fields.Char(string='Customer Reference')
name = fields.Char(string='Quotation')
date_order = fields.Date(string='Quotation Date:')
create_date = fields.Datetime(string='Create Date:')
partner_id = fields.Many2one('res.partner', string = 'Customer')
company_id = fields.Many2one('res.company', string = 'Company')
user_id = fields.Many2one('res.users', string = 'User')
assembly_state = fields.Selection(ASSEMBLY_STATES, string="State PG")
state = fields.Selection(order_states, string="State")
in_company = fields.Boolean(default=False,compute='_in_company',store=False)
number_of_parts = fields.Integer(string='Anzahl Teile')
number_of_parts_open = fields.Integer(string='Teile offen')
number_of_fittings = fields.Integer(string='Anzahl Beschläge')
number_of_fittings_open = fields.Integer(string='Beschläge offen')
@api.multi
def _in_company(self):
sCompany = self.env.user.company_id
for record in self:
if record.company_id == sCompany:
record.in_company = True
@api.model_cr
def init(self):
# print("connected")
drop_view_if_exists(self._cr, 'sale_cart')
self._cr.execute("""CREATE OR REPLACE VIEW sale_cart AS
SELECT so.id AS id,
so.id AS order_id,
so.name AS name,
so.origin AS origin,
so.client_order_ref AS client_order_ref,
so.date_order AS date_order,
so.create_date AS create_date,
so.assembly_state AS assembly_state,
so.state AS state,
so.number_of_parts AS number_of_parts,
so.number_of_parts_open AS number_of_parts_open,
so.number_of_fittings AS number_of_fittings,
so.number_of_fittings_open AS number_of_fittings_open,
so.partner_id AS partner_id,
so.company_id AS company_id,
c_u.user_id AS user_id
FROM sale_order so
INNER JOIN res_company_users_rel c_u ON so.company_id = c_u.cid
WHERE so.state != 'cancel' AND so.origin != '' order by date_order desc
""")
@api.multi
def switch_company(self):
values = {'company_id': self.company_id.id}
self.env.user.write(values)
return {
'type': 'ir.actions.client',
'tag': 'reload_context',
}

View File

@ -41,6 +41,10 @@
<field name="fax" widget="phone" string="Fax"/>
</xpath>
<xpath expr="//field[@name='message_bounce']" position="after">
<field name="property_product_pricelist"/>
</xpath>
<xpath expr="//field[@name='property_product_pricelist']" position="attributes">
<attribute name="attrs">{'readonly':[('portal_managed_pricelist', '=', True)]}</attribute>
</xpath>