diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-03-13 16:24:13 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-03-13 16:24:13 +0700 |
| commit | d3e3a8abf0ae382442c16a7ac6091c7bb872313f (patch) | |
| tree | 52ce38f2497b89dc11ca3ae3b1d9f39fb2afc78e | |
| parent | 00b6739e4f4228c1cc66de0ef63312bc633ae21f (diff) | |
change request purchasing job
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/purchasing_job.py | 48 | ||||
| -rw-r--r-- | indoteknik_custom/models/report_stock_forecasted.py | 27 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_monitoring_detail.py | 12 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 10 | ||||
| -rw-r--r-- | indoteknik_custom/models/sales_order_fullfillment.py | 15 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_monitoring_detail.xml | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 17 |
10 files changed, 113 insertions, 21 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 9d8b9bea..5af30414 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -109,3 +109,4 @@ from . import report_logbook_sj from . import role_permission from . import cust_commision from . import report_stock_forecasted +from . import sales_order_fullfillment diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 4afb3e03..b3c25256 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -1,5 +1,6 @@ -from odoo import fields, models, api, tools +from odoo import fields, models, api, tools, _ import logging +from datetime import datetime _logger = logging.getLogger(__name__) @@ -39,9 +40,54 @@ class PurchasingJob(models.Model): def generate_request_po(self): # print(1) # TODO create document automatic purchase + + current_time = datetime.utcnow() + + automatic_purchase = self.env['automatic.purchase'].create([{ + 'apo_type': 'regular', + 'date_doc': current_time, + }]) + count = 0 for job in self: print(job.product_id.name) + qty_purchase = job.outgoing - (job.onhand + job.incoming) + qty_available = (job.onhand + job.incoming) - job.outgoing + + domain = [ + ('product_id.id', '=', job.product_id.id), + ] + orderby = 'count_trx_po desc, count_trx_po_vendor desc' + purchase_pricelist = self.env['purchase.pricelist'].search(domain, order=orderby, limit=1) + vendor_id = purchase_pricelist.vendor_id + price, taxes = automatic_purchase._get_valid_purchase_price(purchase_pricelist) + last_po_line = self.env['purchase.order.line'].search([('product_id', '=', job.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) + + self.env['automatic.purchase.line'].create([{ + 'automatic_purchase_id': automatic_purchase.id, + 'product_id': job.product_id.id, + 'qty_purchase': qty_purchase, + 'qty_available': qty_available, + 'partner_id': vendor_id.id, + 'last_price': price, + 'taxes_id': taxes, + 'subtotal': qty_purchase * price, + 'last_order_id': last_po_line.order_id.id, + 'last_orderline_id': last_po_line.id, + 'brand_id': job.product_id.product_tmpl_id.x_manufacture.id + }]) + automatic_purchase._create_sales_matching() + automatic_purchase._create_sync_purchasing_job(job) + count += 1 + _logger.info('Create Automatic Purchase Line %s' % job.product_id.name) + return { + 'name': _('Automatic Purchase'), + 'view_mode': 'tree,form', + 'res_model': 'automatic.purchase', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', '=', automatic_purchase.id)], + } class OutstandingSales(models.Model): _name = 'v.sales.outstanding' diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py index 48a17095..7ae93fda 100644 --- a/indoteknik_custom/models/report_stock_forecasted.py +++ b/indoteknik_custom/models/report_stock_forecasted.py @@ -6,26 +6,37 @@ class ReplenishmentReport(models.AbstractModel): @api.model def _get_report_lines(self, product_template_ids, product_variant_ids, wh_location_ids): lines = super(ReplenishmentReport, self)._get_report_lines(product_template_ids, product_variant_ids, wh_location_ids) - result_dict = {} for line in lines: - product_id = line.get('product', {}).get('id') - query = [('product_id', '=', product_id)] document_out = line.get('document_out') order_id = document_out.id if document_out else None + product_id = line.get('product', {}).get('id') + query = [('product_id', '=', product_id)] if order_id: result = self._calculate_result(line) - result_dict.setdefault(order_id, []).append(result) + quantity = line.get('quantity', 0) + result_dict.setdefault(order_id, []).append((result, quantity)) for order_id, results in result_dict.items(): sale_order_lines = self.env['sale.order.line'].search([('order_id', '=', order_id)]) + sales_order = self.env['sale.order'].browse(order_id) + + for result, quantity in results: + fullfillment = self.env['sales.order.fullfillment'].search([('sales_order_id', '=', sales_order.id), ('product_id', '=', product_id)]) + if fullfillment: + fullfillment.reserved_from = result + fullfillment.qty_fullfillment = quantity + continue + + fullfillment.create({ + 'sales_order_id': sales_order.id, + 'product_id': product_id, + 'reserved_from': result, + 'qty_fullfillment': quantity, + }) - concatenated_result = ' ,'.join(results) - - for sale_order_line in sale_order_lines: - sale_order_line.reserved_from = concatenated_result return lines diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index 8c35b1cc..ec5e4711 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -24,16 +24,16 @@ class SaleMonitoringDetail(models.Model): qty_reserved = fields.Integer(string="Qty Reserved") note = fields.Char(string="Note") vendor_id = fields.Many2one('res.partner', string='Vendor') + fullfillment = fields.Char(string="Fullfillment", compute='compute_fullfillment') - def _compute_vendor(self): + def compute_fullfillment(self): for r in self: - sale_lines = self.env['sale.order.line'].search([ - ('order_id', '=', r.sale_order_id.id), + fullfillment = self.env['sales.order.fullfillment'].search([ + ('sales_order_id', '=', r.sale_order_id.id), ('product_id', '=', r.product_id.id), - ]) + ], limit=1) - for line in sale_lines: - r.vendor_id = line.vendor_id.id + r.fullfillment = fullfillment.reserved_from def init(self): tools.drop_view_if_exists(self.env.cr, self._table) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 8b789976..32ffc964 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -9,6 +9,7 @@ _logger = logging.getLogger(__name__) class SaleOrder(models.Model): _inherit = "sale.order" + fullfillment_line = fields.One2many('sales.order.fullfillment', 'sales_order_id', string='Fullfillment') order_sales_match_line = fields.One2many('sales.order.purchase.match', 'sales_order_id', string='Purchase Match Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True) total_margin = fields.Float('Total Margin', compute='_compute_total_margin', help="Total Margin in Sales Order Header") total_percent_margin = fields.Float('Total Percent Margin', compute='_compute_total_percent_margin', help="Total % Margin in Sales Order Header") diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index a140468c..95c9cdfa 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -68,14 +68,12 @@ class SaleOrderLine(models.Model): line.qty_reserved = reserved_qty if reserved_qty > 0: - line._compute_reserved_from() - + self._compute_reserved_from() def _compute_reserved_from(self): - for line in self: - # continue - report_stock_forecasted = self.env['report.stock.report_product_product_replenishment'] - report_stock_forecasted._get_report_data(False, [line.product_id.id]) + for line in self: + report_stock_forecasted = self.env['report.stock.report_product_product_replenishment'] + report_stock_forecasted._get_report_data(False, [line.product_id.id]) def _compute_vendor_subtotal(self): for line in self: diff --git a/indoteknik_custom/models/sales_order_fullfillment.py b/indoteknik_custom/models/sales_order_fullfillment.py new file mode 100644 index 00000000..db6b7369 --- /dev/null +++ b/indoteknik_custom/models/sales_order_fullfillment.py @@ -0,0 +1,15 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +import logging + +_logger = logging.getLogger(__name__) + + +class SalesOrderFullfillment(models.Model): + _name = 'sales.order.fullfillment' + + sales_order_id = fields.Many2one('sale.order', string='Sale Order', index=True, required=True, ondelete='cascade') + product_id = fields.Many2one('product.product', string='Product') + reserved_from = fields.Char(string='Reserved From', copy=False) + qty_fullfillment = fields.Float(string='Qty')
\ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 3ef1aa35..7de5d909 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -107,3 +107,4 @@ access_report_logbook_sj_line,access.report.logbook.sj.line,model_report_logbook access_report_logbook_sj_line,access.report.logbook.sj.line,model_report_logbook_sj_line,,1,1,1,1 access_cust_commision,access.cust.commision,model_cust_commision,,1,1,1,1 access_report_stock_report_product_product_replenishment,access.report.stock.report_product_product_replenishment,model_report_stock_report_product_product_replenishment,,1,1,1,1 +access_sales_order_fullfillment,access.sales.order.fullfillment,model_sales_order_fullfillment,,1,1,1,1
\ No newline at end of file diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml index 5091fb83..ed2bd06f 100755 --- a/indoteknik_custom/views/sale_monitoring_detail.xml +++ b/indoteknik_custom/views/sale_monitoring_detail.xml @@ -25,6 +25,7 @@ decoration-info="status == 'Delivered' or status == 'Invoiced'" /> <field name="note" optional="hide"/> + <field name="fullfillment"/> </tree> </field> </record> @@ -58,6 +59,7 @@ <field name="qty_po_received"/> <field name="qty_so_delivered"/> <field name="qty_so_invoiced"/> + <field name="fullfillment"/> </group> </group> </sheet> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index aa508443..0f21d65f 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -173,6 +173,9 @@ <page string="Matches PO" name="page_matches_po"> <field name="order_sales_match_line" readonly="1"/> </page> + <page string="Fullfillment" name="page_sale_order_fullfillment"> + <field name="fullfillment_line" readonly="1"/> + </page> </page> </field> </record> @@ -240,4 +243,18 @@ </field> </record> </data> + + <data> + <record id="sales_order_fullfillmet_tree" model="ir.ui.view"> + <field name="name">sales.order.fullfillment.tree</field> + <field name="model">sales.order.fullfillment</field> + <field name="arch" type="xml"> + <tree editable="top" create="false"> + <field name="product_id" readonly="1"/> + <field name="reserved_from" readonly="1"/> + <field name="qty_fullfillment" readonly="1"/> + </tree> + </field> + </record> + </data> </odoo>
\ No newline at end of file |
