[IMP] repair: Prevent to Unlink Repair Orders if not draft
Before Commit: -Current Functionality doesn't Restrict Unlink of Order Based on States. -if we delete the invoice linked to repair order the state button of invoice still visible in reapir order and when we click on state button it open new draft invoice. After Commit: -Add Validation on Unlink the order based on State,link unlink order only on draft and cancel state. -Always show the "cancel" button on repair orders.When the orders have been cancelled, only allow to delete them if there is no invoice linked, or if the invoice which is linked can be deleted (is still draft and has never been posted). If we are not in one of those conditions, raise the following error "You cannot delete a repair order which is linked to an invoice which has been posted once." -Add wizard when cancelling a repair order which has a draft invoice linked. task-id: 2198997
This commit is contained in:
committed by
Pratima Gupta
parent
81a5cc2e10
commit
8d52edb2fa
@@ -8,6 +8,10 @@ class AccountMove(models.Model):
|
||||
|
||||
repair_ids = fields.One2many('repair.order', 'invoice_id', readonly=True, copy=False)
|
||||
|
||||
def unlink(self):
|
||||
self.repair_ids.filtered(lambda repair: repair.state != 'cancel').state = '2binvoiced'
|
||||
return super().unlink()
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
||||
@@ -47,13 +47,13 @@ class Repair(models.Model):
|
||||
default_address_id = fields.Many2one('res.partner', compute='_compute_default_address_id')
|
||||
state = fields.Selection([
|
||||
('draft', 'Quotation'),
|
||||
('cancel', 'Cancelled'),
|
||||
('confirmed', 'Confirmed'),
|
||||
('under_repair', 'Under Repair'),
|
||||
('ready', 'Ready to Repair'),
|
||||
('2binvoiced', 'To be Invoiced'),
|
||||
('invoice_except', 'Invoice Exception'),
|
||||
('done', 'Repaired')], string='Status',
|
||||
('done', 'Repaired'),
|
||||
('cancel', 'Cancelled')], string='Status',
|
||||
copy=False, default='draft', readonly=True, tracking=True,
|
||||
help="* The \'Draft\' status is used when a user is encoding a new and unconfirmed repair order.\n"
|
||||
"* The \'Confirmed\' status is used when a user confirms the repair order.\n"
|
||||
@@ -111,6 +111,7 @@ class Repair(models.Model):
|
||||
amount_tax = fields.Float('Taxes', compute='_amount_tax', store=True)
|
||||
amount_total = fields.Float('Total', compute='_amount_total', store=True)
|
||||
tracking = fields.Selection(string='Product Tracking', related="product_id.tracking", readonly=False)
|
||||
invoice_state = fields.Selection(string='Invoice State', related='invoice_id.state')
|
||||
|
||||
@api.depends('partner_id')
|
||||
def _compute_default_address_id(self):
|
||||
@@ -191,6 +192,14 @@ class Repair(models.Model):
|
||||
else:
|
||||
self.location_id = False
|
||||
|
||||
def unlink(self):
|
||||
for order in self:
|
||||
if order.state not in ('draft', 'cancel'):
|
||||
raise UserError(_('You can not delete a repair order once it has been confirmed. You must first cancel it.'))
|
||||
if order.state == 'cancel' and order.invoice_id and order.invoice_id.posted_before:
|
||||
raise UserError(_('You can not delete a repair order which is linked to an invoice which has been posted once.'))
|
||||
return super().unlink()
|
||||
|
||||
def button_dummy(self):
|
||||
# TDE FIXME: this button is very interesting
|
||||
return True
|
||||
@@ -199,7 +208,7 @@ class Repair(models.Model):
|
||||
if self.filtered(lambda repair: repair.state != 'cancel'):
|
||||
raise UserError(_("Repair must be canceled in order to reset it to draft."))
|
||||
self.mapped('operations').write({'state': 'draft'})
|
||||
return self.write({'state': 'draft'})
|
||||
return self.write({'state': 'draft', 'invoice_id': False})
|
||||
|
||||
def action_validate(self):
|
||||
self.ensure_one()
|
||||
@@ -251,10 +260,9 @@ class Repair(models.Model):
|
||||
return True
|
||||
|
||||
def action_repair_cancel(self):
|
||||
if self.filtered(lambda repair: repair.state == 'done'):
|
||||
raise UserError(_("Cannot cancel completed repairs."))
|
||||
if any(repair.invoiced for repair in self):
|
||||
raise UserError(_('The repair order is already invoiced.'))
|
||||
invoice_to_cancel = self.filtered(lambda repair: repair.invoice_id.state == 'draft').invoice_id
|
||||
if invoice_to_cancel:
|
||||
invoice_to_cancel.button_cancel()
|
||||
self.mapped('operations').write({'state': 'cancel'})
|
||||
return self.write({'state': 'cancel'})
|
||||
|
||||
@@ -475,7 +483,7 @@ class Repair(models.Model):
|
||||
repair.write({'repaired': True})
|
||||
vals = {'state': 'done'}
|
||||
vals['move_id'] = repair.action_repair_done().get(repair.id)
|
||||
if not repair.invoiced and repair.invoice_method == 'after_repair':
|
||||
if not repair.invoice_id and repair.invoice_method == 'after_repair':
|
||||
vals['state'] = '2binvoiced'
|
||||
repair.write(vals)
|
||||
return True
|
||||
|
||||
@@ -34,21 +34,22 @@
|
||||
<button name="action_repair_start" attrs="{'invisible': ['&', ('state','!=','confirmed'), '!', '&', ('state','=','ready'), ('invoice_method','=','b4repair')]}"
|
||||
type="object" string="Start Repair" class="oe_highlight"/>
|
||||
<button name="action_repair_end" states="under_repair" type="object" string="End Repair" class="oe_highlight"/>
|
||||
<button name="action_repair_invoice_create" states="2binvoiced" type="object" string="Create Invoice" class="oe_highlight" groups="account.group_account_invoice"/>
|
||||
<button name="action_repair_invoice_create" type="object" string="Create Invoice" class="oe_highlight" groups="account.group_account_invoice" attrs="{'invisible': ['|', ('state', '!=', '2binvoiced'), ('invoice_id', '!=', False)]}"/>
|
||||
<button name="action_send_mail" states="draft" string="Send Quotation" type="object"/>
|
||||
<button name="print_repair_order" states="draft" string="Print Quotation" type="object"/>
|
||||
<button name="action_repair_cancel_draft" states="cancel" string="Set to Draft" type="object"/>
|
||||
<button name="action_repair_cancel" string="Cancel Repair" type="object" attrs="{'invisible':['|',('invoice_method','!=','none'), ('state', 'not in',('confirmed','2binvoiced','ready','under_repair'))]}"/>
|
||||
<button name="action_repair_cancel" states="draft" type="object" string="Cancel Repair"/>
|
||||
<button name="action_repair_cancel" string="Cancel Repair" type="object" confirm="Draft invoices for this order will be cancelled. Do you confirm the action?" attrs="{'invisible':['|', ('state', '=', 'cancel'), ('invoice_state', '!=', 'draft')]}"/>
|
||||
<button name="action_repair_cancel" string="Cancel Repair" type="object" attrs="{'invisible': ['|', ('state','=', 'cancel',), ('invoice_state', '=', 'draft')]}"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done"/>
|
||||
</header>
|
||||
<sheet string="Repairs order">
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<field name="invoice_id" invisible="1"/>
|
||||
<button name="action_created_invoice"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
attrs="{'invisible': ['|', '|', '&',('invoice_method','=','after_repair'), ('state', '!=', 'done'), ('invoice_method', '=', 'none'), ('state','in',('confirmed','2binvoiced','draft'))]}"
|
||||
attrs="{'invisible': [('invoice_id', '=', False)]}"
|
||||
groups="account.group_account_invoice">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_text">1</span>
|
||||
@@ -62,6 +63,7 @@
|
||||
</h1>
|
||||
<group>
|
||||
<group>
|
||||
<field name="invoice_state" invisible="1"/>
|
||||
<field name="tracking" invisible="1" attrs="{'readonly': 1}"/>
|
||||
<field name="product_id" />
|
||||
<field name="product_uom_category_id" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user