diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-25 14:00:02 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-25 14:00:02 +0700 |
| commit | bf6db57611262036be96e2f7cc93e315b208f174 (patch) | |
| tree | 6bd3c63d692dfbd9b9426a5a230d40b4c6117034 | |
| parent | 039bbc5e941b06199b6c44bb8898a4121e312355 (diff) | |
bills pelunasan
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 70 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 7 |
2 files changed, 76 insertions, 1 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index f924174a..c24bdbb3 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -68,6 +68,7 @@ class PurchaseOrder(models.Model): ], string='Printed?', copy=False, tracking=True) date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done') bills_dp_id = fields.Many2one('account.move', string='Bills DP') + bills_pelunasan_id = fields.Many2one('account.move', string='Bills Pelunasan') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match') approve_by = fields.Many2one('res.users', string='Approve By') @@ -89,6 +90,75 @@ class PurchaseOrder(models.Model): else: order.grand_total = order.amount_total + def create_bill_pelunasan(self): + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa bikin bill dp') + + # Check for existing vendor bills with the same reference and partner + existing_bill = self.env['account.move'].search([ + ('ref', '=', self.name), + ('partner_id', '=', self.partner_id.id), + ('move_type', '=', 'in_invoice'), + ('state', 'not in', ['cancel', 'posted']) + ], limit=1) + + if existing_bill: + raise UserError(_('Duplicated vendor reference detected. You probably encoded twice the same vendor bill/credit note: %s') % existing_bill.name) + + current_date = datetime.utcnow() + data_bills = { + 'partner_id': self.partner_id.id, + 'partner_shipping_id': self.partner_id.id, + 'ref': self.name, + 'invoice_date': current_date, + 'date': current_date, + 'move_type': 'in_invoice' + } + + bills = self.env['account.move'].create([data_bills]) + + product_dp = self.env['product.product'].browse(229625) + + data_line_bills = [] + + data_line_bills.append({ + 'move_id': bills.id, + 'product_id': product_dp.id, # product down payment + 'name': '[IT.121456] Down Payment', # product down payment + 'account_id': 401, # Uang Muka persediaan barang dagang + 'quantity': -1, + 'product_uom_id': 1, + 'tax_ids': [(5, 0, 0)] + [(4, tax.id) for tax in product_dp.taxes_id], + }) + + for line in self.order_line: + if line.product_id: + data_line_bills.append({ + 'move_id': bills.id, + 'product_id': line.product_id.id, + 'name': self.name + ": " + line.product_id.display_name, + 'account_id': 439, # Uang Muka persediaan barang dagang + 'quantity': line.product_qty, + 'price_unit': line.price_unit, + 'product_uom_id': line.product_uom.id, + 'tax_ids': [(5, 0, 0)] + [(4, tax.id) for tax in line.taxes_id], + }) + + bills_line = self.env['account.move.line'].create(data_line_bills) + + self.bills_pelunasan_id = bills.id + + return { + 'name': _('Account Move'), + 'view_mode': 'tree,form', + 'res_model': 'account.move', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', '=', bills.id)] + } + + + def create_bill_dp(self): if not self.env.user.is_accounting: raise UserError('Hanya Accounting yang bisa bikin bill dp') diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 3e609f15..06c76a82 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -27,7 +27,11 @@ <button name="delete_line" type="object" string="Delete " states="draft"/> </button> <button name="button_unlock" position="after"> - <button name="create_bill_dp" string="Create Bill DP" type="object" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ('purchase', 'done'))]}"/> + <button name="create_bill_dp" string="Create Bill DP" type="object" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ('purchase', 'done')), ('bills_pelunasan_id', '!=', False)]}"/> + </button> + <button name="button_unlock" position="after"> + <button name="create_bill_pelunasan" string="Create Bill Pelunasan" type="object" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ('purchase', 'done')), ('bills_pelunasan_id', '!=', False)]}"/> + </button> <field name="date_order" position="before"> <field name="sale_order_id" attrs="{'readonly': [('state', 'not in', ['draft'])]}"/> @@ -100,6 +104,7 @@ <field name="approval_edit_line"/> <field name="logbook_bill_id"/> <field name="bills_dp_id" readonly="1"/> + <field name="bills_pelunasan_id" readonly="1"/> </field> <field name="order_line" position="attributes"> |
