From dae117ce9bb219557c9a4fc995e93bc4a88ea03f Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Tue, 11 Oct 2022 15:58:58 +0700 Subject: init commit --- .../models/sale_advance_payment_inv.py | 167 +++++++++++++++++++++ indoteknik_custom/models/sale_monitoring.py | 2 +- indoteknik_custom/models/sale_monitoring_detail.py | 2 +- indoteknik_custom/models/x_manufactures.py | 2 + 4 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 indoteknik_custom/models/sale_advance_payment_inv.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_advance_payment_inv.py b/indoteknik_custom/models/sale_advance_payment_inv.py new file mode 100644 index 00000000..e07d0ee0 --- /dev/null +++ b/indoteknik_custom/models/sale_advance_payment_inv.py @@ -0,0 +1,167 @@ +from odoo import models, fields +from odoo.exceptions import UserError + + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = 'sale.advance.payment.inv' + + def create_invoices(self): + sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', [])) + + if self.advance_payment_method == 'delivered': + sale_orders._create_invoices(final=self.deduct_down_payments) + else: + # Create deposit product if necessary + if not self.product_id: + vals = self._prepare_deposit_product() + self.product_id = self.env['product.product'].create(vals) + self.env['ir.config_parameter'].sudo().set_param('sale.default_deposit_product_id', self.product_id.id) + + sale_line_obj = self.env['sale.order.line'] + for order in sale_orders: + amount, name = self._get_advance_details(order) + + if self.product_id.invoice_policy != 'order': + raise UserError( + _('The product used to invoice a down payment should have an invoice policy set to "Ordered quantities". Please update your deposit product to be able to create a deposit invoice.')) + if self.product_id.type != 'service': + raise UserError( + _("The product used to invoice a down payment should be of type 'Service'. Please use another product or update this product.")) + taxes = self.product_id.taxes_id.filtered( + lambda r: not order.company_id or r.company_id == order.company_id) + tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids + analytic_tag_ids = [] + for line in order.order_line: + analytic_tag_ids = [(4, analytic_tag.id, None) for analytic_tag in line.analytic_tag_ids] + + so_line_values = self._prepare_so_line(order, analytic_tag_ids, tax_ids, amount) + so_line = sale_line_obj.create(so_line_values) + self._create_invoice(order, so_line, amount) + if self._context.get('open_invoices', False): + return sale_orders.action_view_invoice() + return {'type': 'ir.actions.act_window_close'} + + # def _create_invoices(self, grouped=False, final=False, date=None): + # """ + # Create the invoice associated to the SO. + # :param grouped: if True, invoices are grouped by SO id. If False, invoices are grouped by + # (partner_invoice_id, currency) + # :param final: if True, refunds will be generated if necessary + # :returns: list of created invoices + # """ + # if not self.env['account.move'].check_access_rights('create', False): + # try: + # self.check_access_rights('write') + # self.check_access_rule('write') + # except AccessError: + # return self.env['account.move'] + # + # # 1) Create invoices. + # invoice_vals_list = [] + # invoice_item_sequence = 0 # Incremental sequencing to keep the lines order on the invoice. + # for order in self: + # order = order.with_company(order.company_id) + # current_section_vals = None + # down_payments = order.env['sale.order.line'] + # + # invoice_vals = order._prepare_invoice() + # invoiceable_lines = order._get_invoiceable_lines(final) + # + # if not any(not line.display_type for line in invoiceable_lines): + # continue + # + # invoice_line_vals = [] + # down_payment_section_added = False + # for line in invoiceable_lines: + # if not down_payment_section_added and line.is_downpayment: + # # Create a dedicated section for the down payments + # # (put at the end of the invoiceable_lines) + # invoice_line_vals.append( + # (0, 0, order._prepare_down_payment_section_line( + # sequence=invoice_item_sequence, + # )), + # ) + # down_payment_section_added = True + # invoice_item_sequence += 1 + # invoice_line_vals.append( + # (0, 0, line._prepare_invoice_line( + # sequence=invoice_item_sequence, + # )), + # ) + # invoice_item_sequence += 1 + # + # invoice_vals['invoice_line_ids'] += invoice_line_vals + # invoice_vals_list.append(invoice_vals) + # + # if not invoice_vals_list: + # raise self._nothing_to_invoice_error() + # + # # 2) Manage 'grouped' parameter: group by (partner_id, currency_id). + # if not grouped: + # new_invoice_vals_list = [] + # invoice_grouping_keys = self._get_invoice_grouping_keys() + # invoice_vals_list = sorted(invoice_vals_list, key=lambda x: [x.get(grouping_key) for grouping_key in invoice_grouping_keys]) + # for grouping_keys, invoices in groupby(invoice_vals_list, key=lambda x: [x.get(grouping_key) for grouping_key in invoice_grouping_keys]): + # origins = set() + # payment_refs = set() + # refs = set() + # ref_invoice_vals = None + # for invoice_vals in invoices: + # if not ref_invoice_vals: + # ref_invoice_vals = invoice_vals + # else: + # ref_invoice_vals['invoice_line_ids'] += invoice_vals['invoice_line_ids'] + # origins.add(invoice_vals['invoice_origin']) + # payment_refs.add(invoice_vals['payment_reference']) + # refs.add(invoice_vals['ref']) + # ref_invoice_vals.update({ + # 'ref': ', '.join(refs)[:2000], + # 'invoice_origin': ', '.join(origins), + # 'payment_reference': len(payment_refs) == 1 and payment_refs.pop() or False, + # }) + # new_invoice_vals_list.append(ref_invoice_vals) + # invoice_vals_list = new_invoice_vals_list + # + # # 3) Create invoices. + # + # # As part of the invoice creation, we make sure the sequence of multiple SO do not interfere + # # in a single invoice. Example: + # # SO 1: + # # - Section A (sequence: 10) + # # - Product A (sequence: 11) + # # SO 2: + # # - Section B (sequence: 10) + # # - Product B (sequence: 11) + # # + # # If SO 1 & 2 are grouped in the same invoice, the result will be: + # # - Section A (sequence: 10) + # # - Section B (sequence: 10) + # # - Product A (sequence: 11) + # # - Product B (sequence: 11) + # # + # # Resequencing should be safe, however we resequence only if there are less invoices than + # # orders, meaning a grouping might have been done. This could also mean that only a part + # # of the selected SO are invoiceable, but resequencing in this case shouldn't be an issue. + # if len(invoice_vals_list) < len(self): + # SaleOrderLine = self.env['sale.order.line'] + # for invoice in invoice_vals_list: + # sequence = 1 + # for line in invoice['invoice_line_ids']: + # line[2]['sequence'] = SaleOrderLine._get_invoice_line_sequence(new=sequence, old=line[2]['sequence']) + # sequence += 1 + # + # # Manage the creation of invoices in sudo because a salesperson must be able to generate an invoice from a + # # sale order without "billing" access rights. However, he should not be able to create an invoice from scratch. + # moves = self.env['account.move'].sudo().with_context(default_move_type='out_invoice').create(invoice_vals_list) + # + # # 4) Some moves might actually be refunds: convert them if the total amount is negative + # # We do this after the moves have been created since we need taxes, etc. to know if the total + # # is actually negative or not + # if final: + # moves.sudo().filtered(lambda m: m.amount_total < 0).action_switch_invoice_into_refund_credit_note() + # for move in moves: + # move.message_post_with_view('mail.message_origin_link', + # values={'self': move, 'origin': move.line_ids.mapped('sale_line_ids.order_id')}, + # subtype_id=self.env.ref('mail.mt_note').id + # ) + # return moves \ No newline at end of file diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py index a837a6bc..c7f4368a 100755 --- a/indoteknik_custom/models/sale_monitoring.py +++ b/indoteknik_custom/models/sale_monitoring.py @@ -43,7 +43,7 @@ class SaleMonitoring(models.Model): WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA' ELSE 'Belum Invoiced' END AS status, - get_po_number(smd.sale_order_id) as po_number + 0 as po_number FROM sale_monitoring_detail smd GROUP BY smd.date_order, smd.sale_order_id, smd.partner_id, smd.user_id ) diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index 843c7348..07b62d33 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -44,7 +44,7 @@ class SaleMonitoringDetail(models.Model): p.id AS product_id, sol.product_uom_qty AS qty_so, sol.qty_delivered AS qty_so_delivered, - get_qty_to_delivered(sol.id) as qty_to_delivered, + 0 as qty_to_delivered, sol.qty_invoiced AS qty_so_invoiced, so.date_order AS date_order, get_qty_po(so.id, sol.product_id) AS qty_po, diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index e07f724e..b32d257d 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -10,6 +10,8 @@ class XManufactures(models.Model): x_description = fields.Html(string="Description") x_logo_manufacture = fields.Binary(string="Logo Manufacture") x_logo_manufacture_128 = fields.Image("Image 128", related="x_logo_manufacture", max_width=128, max_height=128, store=True) + image_promotion_1 = fields.Binary(string="Promotion Image 1") + image_promotion_2 = fields.Binary(string="Promotion Image 2") x_manufacture_level = fields.Selection([ ('prioritas', 'Prioritas'), ('gold', 'Gold'), -- cgit v1.2.3