Feedback 1216: Flag - Sammelrechnung Kundenstamm
							parent
							
								
									1029d3f540
								
							
						
					
					
						commit
						55a27be83c
					
				|  | @ -56,6 +56,7 @@ class Partner(models.Model): | ||||||
|     active = fields.Boolean(track_visibility='onchange') |     active = fields.Boolean(track_visibility='onchange') | ||||||
|     portal_export_pending = fields.Boolean(string='Portal Export ausständig') |     portal_export_pending = fields.Boolean(string='Portal Export ausständig') | ||||||
|     date_vat_check = fields.Date(string='Datum der letzten UID-Prüfung') |     date_vat_check = fields.Date(string='Datum der letzten UID-Prüfung') | ||||||
|  |     collective_bill = fields.Boolean(string='Sammelrechnung') | ||||||
| 
 | 
 | ||||||
|     _sql_constraints = [ |     _sql_constraints = [ | ||||||
|         ('ref_uniq', 'unique(ref)', 'Die Interne Referenz muss eindeutig sein'), |         ('ref_uniq', 'unique(ref)', 'Die Interne Referenz muss eindeutig sein'), | ||||||
|  |  | ||||||
|  | @ -21,7 +21,8 @@ | ||||||
| from datetime import datetime | from datetime import datetime | ||||||
| 
 | 
 | ||||||
| from odoo import api, fields, models, _ | 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 | from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -207,6 +208,62 @@ class SaleOrder(models.Model): | ||||||
| 
 | 
 | ||||||
|         return res |         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): | class SaleOrderLine(models.Model): | ||||||
|     _inherit = 'sale.order.line' |     _inherit = 'sale.order.line' | ||||||
|  |  | ||||||
|  | @ -54,6 +54,10 @@ | ||||||
|                 <field name="endkunde"/> |                 <field name="endkunde"/> | ||||||
|                 <field name="partner_sector_id"/> |                 <field name="partner_sector_id"/> | ||||||
|             </xpath> |             </xpath> | ||||||
|  | 
 | ||||||
|  |             <xpath expr="//field[@name='property_payment_term_id']" position="before"> | ||||||
|  |                 <field name="collective_bill"/> | ||||||
|  |             </xpath> | ||||||
|         </field> |         </field> | ||||||
|     </record> |     </record> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue