Skip to content

Commit

Permalink
[FIX] l10n_ar_sale: Sale sequence
Browse files Browse the repository at this point in the history
Depending on both sale checkbook and sale order type

Ticket 85984 and 86018

X-original-commit: d8c7a4d
  • Loading branch information
zaoral committed Jan 17, 2025
1 parent 02f9d81 commit 6d6974f
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions l10n_ar_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,25 @@ def _get_sale_checkbook(self):
@api.model_create_multi
def create(self, vals):
for val in vals:
if self.env.user.has_group('l10n_ar_sale.use_sale_checkbook') and \
val.get('name', _('New')) == _('New') and \
val.get('sale_checkbook_id'):
sale_checkbook = self.env['sale.checkbook'].browse(
val.get('sale_checkbook_id'))
val['name'] = sale_checkbook.sequence_id and\
sale_checkbook.sequence_id._next() or _('New')
return super(SaleOrder, self).create(vals)
if val.get('name', _('New')) == _('New'):
sale_checkbook_id = val.get('sale_checkbook_id')
sale_order_type = val.get('type_id')

use_checkbook = self.sudo().env.ref('l10n_ar_sale.use_sale_checkbook').users
object_model = False
object_id = False
if use_checkbook and sale_checkbook_id:
object_model = 'sale.checkbook'
object_id = sale_checkbook_id
elif (use_checkbook and not sale_checkbook_id and sale_order_type) and \
(not use_checkbook and sale_order_type):
object_model = 'sale.order.type'
object_id = sale_order_type

if object_model and object_id:
object_record = self.env[object_model].browse(object_id)
val['name'] = object_record.sequence_id and \
object_record.sequence_id._next() or _('New')

def write(self, vals):
"""A sale checkbook could have a different order sequence, so we could
Expand Down

0 comments on commit 6d6974f

Please sign in to comment.