diff options
Diffstat (limited to 'fixco_custom/models/sale.py')
| -rwxr-xr-x | fixco_custom/models/sale.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index a192928..a36be0f 100755 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -5,11 +5,23 @@ from odoo.exceptions import UserError class SaleOrder(models.Model): _inherit = "sale.order" - carrier = fields.Char(string='Shipping Method') - invoice_mp = fields.Char(string='Invoice Marketplace') - order_reference = fields.Char(string='Order Reference') + carrier = fields.Char(string='Shipping Method', required=True) + invoice_mp = fields.Char(string='Invoice Marketplace', required=True) + order_reference = fields.Char(string='Order Reference', required=True) address = fields.Char('Address') - note_by_buyer = fields.Char('Note By Buyer') + note_by_buyer = fields.Char('Note By Buyer') + + def _check_duplicate_order_id(self): + for rec in self: + so_duplicate = self.search([ + '|', + ('order_reference', '=', rec.order_reference), + ('invoice_mp', '=', rec.invoice_mp), + ('id', '!=', rec.id), + ], limit=1) + + if so_duplicate: + raise UserError(f'Order Id tersebut sudah digunakan di so {so_duplicate.name}') # def open_form_multi_create_invoices(self): # action = self.env['ir.actions.act_window']._for_xml_id('fixco_custom.action_sale_order_multi_invoices') @@ -34,7 +46,7 @@ class SaleOrder(models.Model): 'ref': self.client_order_ref or '', 'move_type': 'out_invoice', 'narration': self.note, - 'transaction_type': self.partner_invoice_id.transaction_type, + 'transaction_type': self.partner_id.transaction_type, 'invoice_marketplace': self.invoice_mp, 'address': self.address, 'sale_id': self.id, @@ -84,3 +96,9 @@ class SaleOrder(models.Model): 'default_partner_name': self.partner_id.name } } + + def action_confirm(self): + for order in self: + order._check_duplicate_order_id() + res = super(SaleOrder, self).action_confirm() + return res
\ No newline at end of file |
