Skip to Content
Menu
This question has been flagged

I have a custom module on Odoo14,


I have do customization that generate sale sale.order automatically after clicking on my custom button.


But for now, I want to do, if Invoice (from account.move) got paid, I want my all of my items on stock.picking get deliver, which is the Invoice and stock.picking is related on the same sale.order.


So far, I try to make it like this:

class AccountMove(models.Model):
_inherit = "account.move"

course_registration_id = fields.Many2one('aqur.course.registration',
string='Course Registration ID', readonly=True, tracking=True,
states={'draft': [('readonly', False)]}, change_default=True)
course_registration_number = fields.Char(related='course_registration_id.course_registration_number',
string='Course Registration Number')

def write(self, vals):
invoice_course = self.env['account.move'].search(
[('course_registration_id', '!=', False), ('course_registration_number', '!=', False)])

for rec in invoice_course:
stock_picking = self.env['stock.picking'].search(
[('course_registration_id', '=', rec.course_registration_id.id),
('course_registration_number', '=', rec.course_registration_number)])

if rec.payment_state == 'paid' and stock_picking:
for mv in stock_picking.move_ids_without_package:
mv.quantity_done = mv.product_uom_qty
stock_picking.button_validate()

return super(AccountMove, self).write(vals)

But I got this message when I do payment on my invoice:

You cannot validate a transfer if no quantities are reserved nor done. To force the transfer, switch in edit mode and encode the done quantities.
I also do testing to fill the quantity done on stock.picking by manually edit on the form,
but when I do register payment on my invoice, I always got the error.

So, whats wrong in my code?,
please, any help, source or tutorial to do achive that will be very appreaciated.

Thanks,
Tri Nanda
Avatar
Discard

Invoice payment and deliveries are not related from a VAT and the logistics Point of View. This does not mske any sense to me.

Author

Hi Ermin, this is for small enough business, the cashier that do register payment on invoice is the same people that deliver the product on stock.picking.

Just to make the process be short,
after a cashier do register payment and the invoice is paid, deliver the product on stock.picking automatically.

why don't just use POS?
for many of reasons on our process and features, we don't use POS for this,
like, our customer should can see their sale and invoice on their own portal, and others considered things.

Related Posts Replies Views Activity
1
Oct 22
1589
0
Jun 22
1154
0
Mar 22
2507
0
Aug 21
1684
0
Jul 16
2401