From 0a200c2288da23dd4f964588ee804381ed230126 Mon Sep 17 00:00:00 2001 From: Andreas Osim Date: Tue, 25 Feb 2025 11:11:09 +0100 Subject: [PATCH] UBL Integration --- ext/custom-addons/dp_custom/models/account.py | 20 +++ .../dp_custom/models/mail_template.py | 28 ++- ext/custom-addons/dp_custom/models/sale.py | 165 +++++++++--------- .../dp_custom/views/res_partner_views.xml | 4 + 4 files changed, 134 insertions(+), 83 deletions(-) diff --git a/ext/custom-addons/dp_custom/models/account.py b/ext/custom-addons/dp_custom/models/account.py index 1c4cf59f..2c76226a 100644 --- a/ext/custom-addons/dp_custom/models/account.py +++ b/ext/custom-addons/dp_custom/models/account.py @@ -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) diff --git a/ext/custom-addons/dp_custom/models/mail_template.py b/ext/custom-addons/dp_custom/models/mail_template.py index 5fbb2269..40cfb4c2 100644 --- a/ext/custom-addons/dp_custom/models/mail_template.py +++ b/ext/custom-addons/dp_custom/models/mail_template.py @@ -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]] diff --git a/ext/custom-addons/dp_custom/models/sale.py b/ext/custom-addons/dp_custom/models/sale.py index f8f11d7b..ddabdd73 100644 --- a/ext/custom-addons/dp_custom/models/sale.py +++ b/ext/custom-addons/dp_custom/models/sale.py @@ -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', + } + diff --git a/ext/custom-addons/dp_custom/views/res_partner_views.xml b/ext/custom-addons/dp_custom/views/res_partner_views.xml index 54b86422..5abbad78 100644 --- a/ext/custom-addons/dp_custom/views/res_partner_views.xml +++ b/ext/custom-addons/dp_custom/views/res_partner_views.xml @@ -41,6 +41,10 @@ + + + + {'readonly':[('portal_managed_pricelist', '=', True)]}