diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-04-24 13:45:43 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-04-24 13:45:43 +0700 |
| commit | 68c7f85b0bf7b8eb85f5bbffcfe2bbc8a38b7e4e (patch) | |
| tree | e9982aa981deb8b9d7c42a51322f897ac38e6d0b | |
| parent | 5840f4fce3776a6c14a8f46ed156284b301d8af1 (diff) | |
update purchasing job
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 5 | ||||
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 19 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 10 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_move.xml | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/automatic_purchase.xml | 1 |
5 files changed, 31 insertions, 5 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 5afd174f..b306b6af 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -65,10 +65,7 @@ class AccountMove(models.Model): @api.model def create(self, vals): - if 'flag_delivery_amt' in vals and vals['flag_delivery_amt']: - vals['nomor_kwitansi'] = self.env['ir.sequence'].next_by_code('nomor.kwitansi') or '0' - else: - vals['nomor_kwitansi'] = None + vals['nomor_kwitansi'] = self.env['ir.sequence'].next_by_code('nomor.kwitansi') or '0' result = super(AccountMove, self).create(vals) return result diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 94cf686e..70b6969e 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -252,14 +252,24 @@ class AutomaticPurchase(models.Model): 'suggest': product._get_po_suggest(line.qty_purchase), 'product_uom_qty': line.qty_purchase, 'price_unit': line.last_price, + 'taxes_id': [line.taxes_id.id], # 'so_line_id': [sales.sale_line_id.id for sales in sales_match], } new_po_line = self.env['purchase.order.line'].create([param_line]) line.current_po_id = new_po.id line.current_po_line_id = new_po_line.id + self.update_purchase_price_so_line(line) self.create_purchase_order_sales_match(new_po) + def update_purchase_price_so_line(self, apo): + sales_match = self.env['automatic.purchase.sales.match'].search([ + ('automatic_purchase_id', '=', self.id), + ('product_id', '=', apo.product_id.id), + ]) + + for sales in sales_match: + sales.sale_line_id.purchase_price = apo.last_price def create_purchase_order_sales_match(self, purchase_order): matches_so_product_ids = [line.product_id.id for line in purchase_order.order_line] @@ -360,7 +370,8 @@ class AutomaticPurchase(models.Model): automatic_purchase.notification = "Automatic PO Created %s Lines" % count automatic_purchase._create_sales_matching() automatic_purchase._create_sync_purchasing_job(jobs) - print(1) + + return automatic_purchase.id def _create_sales_matching(self): for line in self.purchase_lines: @@ -375,6 +386,10 @@ class AutomaticPurchase(models.Model): ('product_id', '=', sale.product_id.id), ]) + price_so = self.env['sale.order.line'].search([ + ('id', '=', sale.sale_line_id.id), + ]) + if existing_match: continue @@ -390,6 +405,7 @@ class AutomaticPurchase(models.Model): 'product_id': sale.product_id.id, 'qty_so': sale.outgoing, 'qty_po': line.qty_purchase, + 'purchase_price': price_so.purchase_price, }]) def _create_sync_purchasing_job(self, jobs): @@ -541,6 +557,7 @@ class AutomaticPurchaseSalesMatch(models.Model): product_id = fields.Many2one('product.product', string='Product') qty_so = fields.Float(string='Qty SO') qty_po = fields.Float(string='Qty PO') + purchase_price = fields.Float(string='Purchase Price SO') class SyncPurchasingJob(models.Model): diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index b9c4011e..93b235d8 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -40,6 +40,16 @@ class PurchaseOrderLine(models.Model): delete_line = fields.Boolean(string='Delete', default=False, help='centang ini jika anda ingin menghapus line ini') is_edit_product_qty = fields.Boolean(string='Is Edit Product Qty', compute='_compute_is_edit_product_qty') + @api.constrains('purchase_price') + def constrains_purchase_price(self): + for line in self: + matches_so = self.env['purchase.order.sales.match'].search([ + ('purchase_order_id', '=', line.order_id.id), + ('product_id', '=', line.product_id.id), + ]) + + line.purchase_price = matches_so.sale_line_id.purchase_price + @api.constrains('product_qty') def constrains_product_qty(self): for line in self: diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml index 606a8b24..1be6d118 100644 --- a/indoteknik_custom/views/account_move.xml +++ b/indoteknik_custom/views/account_move.xml @@ -50,6 +50,7 @@ <field name="date_terima_tukar_faktur"/> <field name="due_extension"/> <field name="counter"/> + <field name="nomor_kwitansi"/> </field> <field name="to_check" position="after"> <field name="already_paid"/> diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml index a505daa5..71d292c9 100644 --- a/indoteknik_custom/views/automatic_purchase.xml +++ b/indoteknik_custom/views/automatic_purchase.xml @@ -52,6 +52,7 @@ <field name="partner_id" readonly="1" optional="hide"/> <field name="partner_invoice_id" readonly="1"/> <field name="salesperson_id" readonly="1"/> + <field name="purchase_price" readonly="1"/> <field name="product_id" readonly="1"/> <field name="qty_so" readonly="1"/> <field name="qty_po" readonly="1"/> |
