diff options
| author | Stephan Christianus <stephanchrst@gmail.com> | 2023-01-16 10:02:53 +0000 |
|---|---|---|
| committer | Stephan Christianus <stephanchrst@gmail.com> | 2023-01-16 10:02:53 +0000 |
| commit | f3d44eb32705c07c28f688300d54c36e7e26bd10 (patch) | |
| tree | 69e3fa5c1a5b28da935435440d3eb99ef2a2117c | |
| parent | 4cec68ef40a33071d949c33c1592c146779f1abe (diff) | |
| parent | f960f1c092cdb7669152f8caca7afad314a59877 (diff) | |
Merged in release (pull request #24)
Release
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 39 | ||||
| -rw-r--r-- | indoteknik_custom/models/dunning_run.py | 75 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 7 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/views/dunning_run.xml | 31 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_manufactures.xml | 3 |
6 files changed, 104 insertions, 55 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 28a63ed5..2e8e0226 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,6 +1,7 @@ from .. import controller from odoo import http from odoo.http import request +from datetime import datetime, timedelta import ast @@ -12,20 +13,44 @@ class Product(controller.Controller): if not self.authenticate(): return self.response(code=401, description='Unauthorized') base_url = request.env['ir.config_parameter'].get_param('web.base.url') - query = [('show_as_new_product', '=', True)] - brands = request.env['x_manufactures'].search(query, order='sequence') + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + query_products = [ + ('type', '=', 'product'), + ('active', '=', True), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), + ] + new_products = request.env['product.template'].search(query_products, order='name', limit=500) + brands = [] + for product in new_products: + brands.append(product.x_manufacture) + brands = list(dict.fromkeys(brands)) + data = [] + count = 0 for brand in brands: - query_products = [ - ('is_new_product', '=', True), + count += 1 + if count == 11: + break + query = [ + ('type', '=', 'product'), + ('active', '=', True), ('x_manufacture', '=', brand.id), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), ] - products = request.env['product.template'].search(query_products, order='name') + products = request.env['product.template'].search(query, order='name', limit=36) data.append({ 'manufacture_id': brand.id, - 'sequence': brand.sequence, + 'sequence': brand.sequence if brand.sequence else count, 'name': brand.x_name, - 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(brand.id) if brand.x_logo_manufacture else '', + 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str( + brand.id) if brand.x_logo_manufacture else '', 'products': [request.env['product.template'].api_single_response(x) for x in products] }) return self.response(data) diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index ed9aa7c0..56a33578 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -17,8 +17,37 @@ class DunningRun(models.Model): required=True, change_default=True, index=True, tracking=1) dunning_line = fields.One2many('dunning.run.line', 'dunning_id', string='Dunning Lines', auto_join=True) # dunning_level = fields.Integer(string='Dunning Level', default=30, help='30 hari sebelum jatuh tempo invoice') + date_kirim_tukar_faktur = fields.Date(string='Kirim Faktur') + resi_tukar_faktur = fields.Char(string='Resi Faktur') + date_terima_tukar_faktur = fields.Date(string='Terima Faktur') + shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur') + is_validated = fields.Boolean(string='Validated') + + def copy_date_faktur(self): + if not self.is_validated: + raise UserError('Harus di validate dulu') + for line in self.dunning_line: + invoice = line.invoice_id + if not invoice.date_kirim_tukar_faktur: + invoice.date_kirim_tukar_faktur = self.date_kirim_tukar_faktur + if not invoice.resi_tukar_faktur: + invoice.resi_tukar_faktur = self.resi_tukar_faktur + if not invoice.date_terima_tukar_faktur: + invoice.date_terima_tukar_faktur = self.date_terima_tukar_faktur + if not invoice.shipper_faktur_id: + invoice.shipper_faktur_id = self.shipper_faktur_id + + def validate_dunning(self): + if not self.dunning_line: + raise UserError('Dunning Line masih kosong, generate dulu') + else: + self.is_validated = True def generate_dunning_line(self): + if self.is_validated: + raise UserError('Sudah di validate, tidak bisa digenerate ulang') + if self.dunning_line: + raise UserError('Harus hapus semua line jika ingin generate ulang') if self.partner_id.parent_id: raise UserError('Harus pilih parent company') @@ -29,21 +58,26 @@ class DunningRun(models.Model): for partner in partners: query = [ ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), ('partner_id', '=', partner.id), - ('outstanding_amount', '>', 0), + ('amount_residual_signed', '>', 0), ] invoices = self.env['account.move'].search(query, order='invoice_date') + count = 0 for invoice in invoices: - parameter_line = { + self.env['dunning.run.line'].create([{ 'dunning_id': self.id, - 'partner_id': invoice.partner_id, + 'partner_id': invoice.partner_id.id, 'invoice_id': invoice.id, 'date_invoice': invoice.invoice_date, - 'efaktur_id': invoice.efaktur_id, + 'efaktur_id': invoice.efaktur_id.id, 'reference': invoice.ref, - 'open_amt': invoice.outstanding_amount - } - self.env['dunning.run.line'].create([parameter_line]) + 'total_amt': invoice.amount_total, + 'open_amt': invoice.amount_residual_signed, + 'due_date': invoice.invoice_date_due + }]) + count += 1 + _logger.info("Dunning Line generated %s" % count) @api.model def create(self, vals): @@ -51,33 +85,6 @@ class DunningRun(models.Model): result = super(DunningRun, self).create(vals) return result - def generate_dunning_line(self): - # validation - if not self.partner_id: - raise UserError('Customer harus diisi') - - invoices = self.env['account.move'].search([ - ('amount_residual_signed', '>', 0), - ('partner_id', '=', self.partner_id.id), - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ]) - count = 0 - for invoice in invoices: - self.env['dunning.run.line'].create([{ - 'dunning_id': self.id, - 'partner_id': invoice.partner_id.id, - 'invoice_id': invoice.id, - 'date_invoice': invoice.invoice_date, - 'efaktur_id': invoice.efaktur_id.id, - 'reference': invoice.ref, - 'total_amt': invoice.amount_total, - 'open_amt': invoice.amount_residual_signed, - 'due_date': invoice.invoice_date_due - }]) - count += 1 - _logger.info("Dunning Line generated %s" % count) - class DunningRunLine(models.Model): _name = 'dunning.run.line' diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index ef0ead1b..74b4edb1 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -57,7 +57,6 @@ class ProductTemplate(models.Model): current_time = datetime.now() delta_time = current_time - timedelta(days=30) - #current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ @@ -65,7 +64,7 @@ class ProductTemplate(models.Model): ('active', '=', True), ('product_rating', '>', 3), ('create_date', '>=', delta_time), - ], limit=1000) + ], limit=100) seq = 0 for product in products: @@ -146,7 +145,7 @@ class ProductTemplate(models.Model): ('active', '=', True), ('last_calculate_rating', '=', False), # ('id', '=', 22798), - ], limit=10000) + ], limit=100) for product in products: # print("Calculate Rating Product ", product) @@ -171,7 +170,7 @@ class ProductTemplate(models.Model): ('type', '=', 'product'), ('active', '=', True), ('last_calculate_rating', '<', delta_time), - ], limit=10000) + ], limit=100) for product in products: print("Calculate Rating Product OutOfDate", product) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index d19214d2..84a374c5 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -145,10 +145,8 @@ class StockPicking(models.Model): continue raise UserError('Sudah pernah dikirim kalender') - is_delivered_validation = self.env['ir.config_parameter'].get_param( - 'stock_picking.qty_delivered_validation') for line in self.move_line_ids_without_package: - if line.move_id.sale_line_id and self.picking_type_id.code == 'outgoing' and is_delivered_validation == 'Y': + if line.move_id.sale_line_id and self.picking_type_id.code == 'outgoing': if line.move_id.sale_line_id.qty_delivered + line.qty_done > line.move_id.sale_line_id.product_uom_qty: raise UserError("Qty Delivered akan lebih dari Qty SO") diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index ab01d476..c251b206 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -5,10 +5,14 @@ <field name="model">dunning.run</field> <field name="arch" type="xml"> <tree> - <field name="id"/> <field name="number"/> <field name="dunning_date"/> <field name="partner_id"/> + <field name="is_validated" readonly="1"/> + <field name="date_kirim_tukar_faktur"/> + <field name="resi_tukar_faktur"/> + <field name="date_terima_tukar_faktur"/> + <field name="shipper_faktur_id"/> </tree> </field> </record> @@ -39,14 +43,33 @@ <div class="oe_button_box" name="button_box"/> <group> <group> - <field name="number"/> - <field name="partner_id"/> - <field name="dunning_date"/> + <div> <button name="generate_dunning_line" string="Generate" type="object" + class="mr-2 oe_highlight oe_edit_only" + /> + <button name="validate_dunning" + string="Validate" + type="object" + class="mr-2 oe_highlight oe_edit_only" + /> + <button name="copy_date_faktur" + string="Copy Date" + type="object" class="oe_highlight oe_edit_only" /> + </div> + <field name="number"/> + <field name="partner_id"/> + <field name="dunning_date"/> + </group> + <group> + <field name="is_validated" readonly="1"/> + <field name="date_kirim_tukar_faktur"/> + <field name="resi_tukar_faktur"/> + <field name="date_terima_tukar_faktur"/> + <field name="shipper_faktur_id"/> </group> </group> <notebook> diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index cc8fd10c..e51cb6a7 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -43,7 +43,6 @@ <field name="x_manufacture_level"/> <field name="x_produk_aksesoris_sparepart"/> <field name="cache_reset_status"/> - <field name="show_as_new_product"/> <field name="sequence"/> </group> <group> @@ -64,8 +63,6 @@ <field name="create_date"/> <field name="solr_flag"/> <field name="product_rating"/> - <field name="is_new_product"/> - <field name="seq_new_product"/> </tree> </field> </page> |
