mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] product_cores: to Odoo 14.0
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
{
|
||||
'name': 'Product Cores',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'version': '13.0.1.0.1',
|
||||
'version': '14.0.1.0.0',
|
||||
'category': 'Tools',
|
||||
'license': 'OPL-1',
|
||||
'summary': 'Charge customers core deposits.',
|
||||
|
||||
@@ -7,32 +7,32 @@ from odoo import models
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def post(self):
|
||||
def _post(self, soft=True):
|
||||
if self._context.get('move_reverse_cancel'):
|
||||
return super(AccountMove, self).post()
|
||||
return super(AccountMove, self)._post(soft)
|
||||
self._product_core_set_date_maturity()
|
||||
return super(AccountMove, self).post()
|
||||
return super(AccountMove, self)._post(soft)
|
||||
|
||||
def _product_core_set_date_maturity(self):
|
||||
for move in self:
|
||||
for line in move.invoice_line_ids.filtered(lambda l: l.product_id.core_ok and l.product_id.type == 'service'):
|
||||
regular_date_maturity = line.date + timedelta(days=(line.product_id.product_core_validity or 0))
|
||||
if move.type in ('in_invoice', 'in_refund', 'in_receipt'):
|
||||
if move.move_type in ('in_invoice', 'in_refund', 'in_receipt'):
|
||||
# derive from purchase
|
||||
if move.type == 'in_refund' and line.purchase_line_id:
|
||||
if move.move_type == 'in_refund' and line.purchase_line_id:
|
||||
# try to date from original
|
||||
po_move_lines = self.search([('purchase_line_id', '=', line.purchase_line_id.id)])
|
||||
po_move_lines = po_move_lines.filtered(lambda l: l.move_id.type == 'in_invoice')
|
||||
po_move_lines = po_move_lines.filtered(lambda l: l.move_id.move_type == 'in_invoice')
|
||||
if po_move_lines:
|
||||
line.date_maturity = po_move_lines[0].date_maturity or regular_date_maturity
|
||||
else:
|
||||
line.date_maturity = regular_date_maturity
|
||||
else:
|
||||
line.date_maturity = regular_date_maturity
|
||||
elif move.type in ('out_invoice', 'out_refund', 'out_receipt'):
|
||||
elif move.move_type in ('out_invoice', 'out_refund', 'out_receipt'):
|
||||
# derive from sale
|
||||
if move.type == 'out_refund' and line.sale_line_ids:
|
||||
other_move_lines = line.sale_line_ids.mapped('invoice_lines').filtered(lambda l: l.move_id.type == 'out_invoice')
|
||||
if move.move_type == 'out_refund' and line.sale_line_ids:
|
||||
other_move_lines = line.sale_line_ids.mapped('invoice_lines').filtered(lambda l: l.move_id.move_type == 'out_invoice')
|
||||
if other_move_lines:
|
||||
line.date_maturity = other_move_lines[0].date_maturity or regular_date_maturity
|
||||
else:
|
||||
|
||||
@@ -125,7 +125,7 @@ class TestProductCores(common.TransactionCase):
|
||||
f.purchase_id = purchase
|
||||
vendor_bill = f.save()
|
||||
self.assertEqual(len(vendor_bill.invoice_line_ids), 2)
|
||||
vendor_bill.post()
|
||||
vendor_bill.action_post()
|
||||
for line in vendor_bill.invoice_line_ids:
|
||||
pol = purchase.order_line.filtered(lambda l: l.product_id == line.product_id)
|
||||
self.assertTrue(pol)
|
||||
@@ -209,9 +209,10 @@ class TestProductCores(common.TransactionCase):
|
||||
sale.picking_ids.action_assign()
|
||||
|
||||
self.assertEqual(so_line.product_uom_qty, sale.picking_ids.move_lines.reserved_availability)
|
||||
res_dict = sale.picking_ids.button_validate()
|
||||
wizard = self.env[(res_dict.get('res_model'))].browse(res_dict.get('res_id'))
|
||||
wizard.process()
|
||||
for move_line in sale.picking_ids.mapped('move_lines.move_line_ids'):
|
||||
move_line.qty_done = move_line.product_uom_qty
|
||||
sale.picking_ids.button_validate()
|
||||
self.assertEqual(sale.picking_ids.state, 'done')
|
||||
self.assertEqual(so_line.qty_delivered, so_line.product_uom_qty)
|
||||
|
||||
# Ensure all products are delivered.
|
||||
@@ -243,8 +244,8 @@ class TestProductCores(common.TransactionCase):
|
||||
|
||||
return_picking = sale.picking_ids.filtered(lambda p: p.state != 'done')
|
||||
self.assertTrue(return_picking)
|
||||
res_dict = return_picking.button_validate()
|
||||
wizard = self.env[(res_dict.get('res_model'))].browse(res_dict.get('res_id'))
|
||||
wizard.process()
|
||||
for move_line in return_picking.mapped('move_lines.move_line_ids'):
|
||||
move_line.qty_done = move_line.product_uom_qty
|
||||
return_picking.button_validate()
|
||||
|
||||
self.assertTrue(all(l.qty_delivered == 0.0 for l in sale.order_line))
|
||||
|
||||
Reference in New Issue
Block a user