From 1029d3f5403866abcb8262867271dad17d808a95 Mon Sep 17 00:00:00 2001 From: Ahmed Aly Date: Thu, 14 Dec 2017 15:52:33 +0100 Subject: [PATCH 1/2] Fall 4423: Auftrag --- ext/custom-addons/dp_custom/models/sale.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ext/custom-addons/dp_custom/models/sale.py b/ext/custom-addons/dp_custom/models/sale.py index a0734926..8532fd13 100644 --- a/ext/custom-addons/dp_custom/models/sale.py +++ b/ext/custom-addons/dp_custom/models/sale.py @@ -31,13 +31,13 @@ class SaleOrder(models.Model): ASSEMBLY_STATES = [('approved', 'Produktionsfreigabe'), ('started', 'Produktion begonnen'), - ('done', 'Produktions fertig'), + ('done', 'Produktion fertig'), ('packed', 'Verpackt'), ('delivered', 'Geliefert')] assembled = fields.Boolean(string='Zusammengebaut') line_id = fields.Many2one(comodel_name='res.line', string='Produktionslinie') - assembly_state = fields.Selection(ASSEMBLY_STATES, string="Status PG") + assembly_state = fields.Selection(ASSEMBLY_STATES, string="Status PG", track_visibility='onchange') quote_name = fields.Char(compute='_compute_quote_name') internal_notes = fields.Text() assembly_notes = fields.Text() @@ -199,6 +199,14 @@ class SaleOrder(models.Model): return ['origin', 'client_order_ref', 'note', 'date_order', 'assembled', 'line_id', 'partner_id', 'fiscal_position_id', 'user_id', 'payment_term_id', 'partner_delivery_id', 'partner_invoice_id'] + @api.multi + def write(self, vals): + res = super(SaleOrder, self).write(vals) + if vals.get('assembly_state', False) and vals.get('assembly_state', False) == 'done': + self.message_post(body='Produktion fertig') + + return res + class SaleOrderLine(models.Model): _inherit = 'sale.order.line' From 55a27be83cf65fcfce142b97f007360f443b7734 Mon Sep 17 00:00:00 2001 From: Ahmed Aly Date: Thu, 14 Dec 2017 16:18:16 +0100 Subject: [PATCH 2/2] Feedback 1216: Flag - Sammelrechnung Kundenstamm --- .../dp_custom/models/res_partner.py | 1 + ext/custom-addons/dp_custom/models/sale.py | 59 ++++++++++++++++++- .../dp_custom/views/res_partner_views.xml | 4 ++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/ext/custom-addons/dp_custom/models/res_partner.py b/ext/custom-addons/dp_custom/models/res_partner.py index d0544165..b99ecebc 100644 --- a/ext/custom-addons/dp_custom/models/res_partner.py +++ b/ext/custom-addons/dp_custom/models/res_partner.py @@ -56,6 +56,7 @@ class Partner(models.Model): active = fields.Boolean(track_visibility='onchange') portal_export_pending = fields.Boolean(string='Portal Export ausständig') date_vat_check = fields.Date(string='Datum der letzten UID-Prüfung') + collective_bill = fields.Boolean(string='Sammelrechnung') _sql_constraints = [ ('ref_uniq', 'unique(ref)', 'Die Interne Referenz muss eindeutig sein'), diff --git a/ext/custom-addons/dp_custom/models/sale.py b/ext/custom-addons/dp_custom/models/sale.py index 8532fd13..1f7ad61f 100644 --- a/ext/custom-addons/dp_custom/models/sale.py +++ b/ext/custom-addons/dp_custom/models/sale.py @@ -21,7 +21,8 @@ from datetime import datetime from odoo import api, fields, models, _ -from odoo.exceptions import ValidationError +from odoo.tools import float_is_zero +from odoo.exceptions import ValidationError, UserError from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT @@ -207,6 +208,62 @@ class SaleOrder(models.Model): return res + @api.multi + def action_invoice_create(self, grouped=False, final=False): + inv_obj = self.env['account.invoice'] + precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') + invoices = {} + references = {} + for order in self: + collective_bill = order.partner_id.collective_bill and "x" or order.id + group_key = order.id if grouped else (collective_bill, order.partner_invoice_id.id, order.currency_id.id) + for line in order.order_line.sorted(key=lambda l: l.qty_to_invoice < 0): + if float_is_zero(line.qty_to_invoice, precision_digits=precision): + continue + if group_key not in invoices: + inv_data = order._prepare_invoice() + invoice = inv_obj.create(inv_data) + references[invoice] = order + invoices[group_key] = invoice + elif group_key in invoices: + vals = {} + if order.name not in invoices[group_key].origin.split(', '): + vals['origin'] = invoices[group_key].origin + ', ' + order.name + if order.client_order_ref and order.client_order_ref not in invoices[group_key].name.split( + ', ') and order.client_order_ref != invoices[group_key].name: + vals['name'] = invoices[group_key].name + ', ' + order.client_order_ref + invoices[group_key].write(vals) + if line.qty_to_invoice > 0: + line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice) + elif line.qty_to_invoice < 0 and final: + line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice) + + if references.get(invoices.get(group_key)): + if order not in references[invoices[group_key]]: + references[invoice] = references[invoice] | order + + if not invoices: + raise UserError(_('There is no invoicable line.')) + + for invoice in invoices.values(): + if not invoice.invoice_line_ids: + raise UserError(_('There is no invoicable line.')) + # If invoice is negative, do a refund invoice instead + if invoice.amount_untaxed < 0: + invoice.type = 'out_refund' + for line in invoice.invoice_line_ids: + line.quantity = -line.quantity + # Use additional field helper function (for account extensions) + for line in invoice.invoice_line_ids: + line._set_additional_fields(invoice) + # Necessary to force computation of taxes. In account_invoice, they are triggered + # by onchanges, which are not triggered when doing a create. + invoice.compute_taxes() + invoice.message_post_with_view('mail.message_origin_link', + values={'self': invoice, 'origin': references[invoice]}, + subtype_id=self.env.ref('mail.mt_note').id) + return [inv.id for inv in invoices.values()] + class SaleOrderLine(models.Model): _inherit = 'sale.order.line' 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 c16384f3..617e6ca9 100644 --- a/ext/custom-addons/dp_custom/views/res_partner_views.xml +++ b/ext/custom-addons/dp_custom/views/res_partner_views.xml @@ -54,6 +54,10 @@ + + + +