Code Monkey home page Code Monkey logo

Comments (7)

kwoychesko avatar kwoychesko commented on August 11, 2024

In om_account_asset/models/account_move.py we can override move_id's button_draft method to look for assets created by the move and then unlink them (see code below). But the asset.unlink method will only allow an asset to be deleted if the asset is in 'draft' state. It's possible that some or all of the assets created by the move are not in 'draft' state.

My question is: what should the business logic be? As written below, if any of the assets created by the invoice or bill have a state != 'draft', the following would result:

  1. none of the assets would be deleted (even the ones that are in 'draft' state),
  2. a UserError is raised such that the invoice or bill would not actually be changed to the draft state.

It would then be up to the user to address the situation as best they can. I'm not sure this is the best solution though. Other business logic options are:

  1. Instead of trying to unlink the assets, we merely inform the user that there exists assets that were created by the move that they just deleted.
  2. We delete any assets that are in 'draft' state and inform the user that there were other assets that could not be handled.
  3. We disallow setting an invoice/bill back to draft (I'm not a fan of this option).

Thoughts? Thank you,
Ken

om_account_asset/models/account_move.py

def button_draft(self):
    # we want to do the native button_draft function steps first to give it a chance to error-out before our steps
    res = super(AccountMove, self).button_draft()

    for move in self:
        if move.state == 'draft':
            # the invoice was successfully set to draft state, therefore delete assets created by this move
            move_assets = self.env["account.asset.asset"].search([("invoice_id", "=", move.id)])
            move_assets.unlink()

    return True

from odooapps.

odoomates avatar odoomates commented on August 11, 2024

Thanks for reporting the issues, we will look at the issues and will get back to you.

from odooapps.

odoomates avatar odoomates commented on August 11, 2024

How about keeping the assets as inactive instead of deleting them ? Upon checking v11, seems instead of deleting, records are set to active False.

def button_draft(self):
res = super(AccountMove, self).button_draft()
for move in self:
if move.state == 'draft':
self.env['account.asset.asset'].search(
[('invoice_id', 'in', self.ids)]).write({'active': False})
return res

Your thoughts ? @kwoychesko

from odooapps.

kwoychesko avatar kwoychesko commented on August 11, 2024

I think setting active to False is a better idea than deleting the asset--great idea! We could even add a message to the chatter about why.

Unfortunately we still have the problem of duplicate assets being created if any of the assets were already approved.

from odooapps.

odoomates avatar odoomates commented on August 11, 2024

one more enhancement is added related to this, validation error will be shown now upon resetting the invoice when there is a asset in non drafted state.
See: a7531b7

from odooapps.

odoomates avatar odoomates commented on August 11, 2024

updated: a7531b7

can you review and shall we close this ?

from odooapps.

kwoychesko avatar kwoychesko commented on August 11, 2024

Looks great! Thanks!

from odooapps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.