bemade_fsm: add visits to sale orders. Fixes #66.
This commit is contained in:
parent
e1a923466c
commit
cf3fccfa32
3 changed files with 44 additions and 12 deletions
|
|
@ -20,7 +20,7 @@ class FSMVisit(models.Model):
|
||||||
is_completed = fields.Boolean(string="Completed",
|
is_completed = fields.Boolean(string="Completed",
|
||||||
related="so_section_id.is_fully_delivered")
|
related="so_section_id.is_fully_delivered")
|
||||||
is_invoiced = fields.Boolean(string="Invoiced",
|
is_invoiced = fields.Boolean(string="Invoiced",
|
||||||
compute="_compute_is_invoiced")
|
related="so_section_id.is_fully_delivered_and_invoiced")
|
||||||
|
|
||||||
def _compute_is_invoiced(self):
|
def _compute_is_invoiced(self):
|
||||||
self.is_invoiced = False
|
self.is_invoiced = False
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,13 @@ class SaleOrderLine(models.Model):
|
||||||
inverse_name="so_section_id",
|
inverse_name="so_section_id",
|
||||||
string="Visit")
|
string="Visit")
|
||||||
is_fully_delivered = fields.Boolean(string="Fully Delivered",
|
is_fully_delivered = fields.Boolean(string="Fully Delivered",
|
||||||
compute="_compute_is_fully_delivered")
|
compute="_compute_is_fully_delivered",
|
||||||
|
help="Indicates whether a line or all the lines in a section have been"
|
||||||
|
"entirely delivered.")
|
||||||
|
is_fully_delivered_and_invoiced = fields.Boolean(string="Fully Invoiced",
|
||||||
|
compute="_compute_is_fully_invoiced",
|
||||||
|
help="Indicates whether a line or all the lines in a section have been"
|
||||||
|
"entirely delivered and invoiced.")
|
||||||
|
|
||||||
def _timesheet_create_task(self, project):
|
def _timesheet_create_task(self, project):
|
||||||
""" Generate task for the given so line, and link it.
|
""" Generate task for the given so line, and link it.
|
||||||
|
|
@ -130,23 +136,30 @@ class SaleOrderLine(models.Model):
|
||||||
@api.depends('order_id.order_line', 'display_type', 'qty_to_deliver', 'order_id.order_line.qty_to_deliver',
|
@api.depends('order_id.order_line', 'display_type', 'qty_to_deliver', 'order_id.order_line.qty_to_deliver',
|
||||||
'order_id.order_line.display_type')
|
'order_id.order_line.display_type')
|
||||||
def _compute_is_fully_delivered(self):
|
def _compute_is_fully_delivered(self):
|
||||||
|
self.is_fully_delivered = self._iterate_items_compute_bool(lambda l: l.qty_to_deliver == 0)
|
||||||
|
|
||||||
|
@api.depends('is_fully_delivered')
|
||||||
|
def _compute_is_fully_invoiced(self):
|
||||||
|
if not self.is_fully_delivered:
|
||||||
|
self.is_fully_delivered_and_invoiced = False
|
||||||
|
return
|
||||||
|
self.is_fully_delivered_and_invoiced = self._iterate_items_compute_bool(lambda l: l.qty_to_invoice == 0)
|
||||||
|
|
||||||
|
def _iterate_items_compute_bool(self, single_line_func):
|
||||||
if not self.display_type:
|
if not self.display_type:
|
||||||
self.is_fully_delivered = self.qty_to_deliver == 0
|
return single_line_func(self)
|
||||||
elif self.display_type == 'line_note':
|
elif self.display_type == 'line_note':
|
||||||
self.is_fully_delivered = True
|
return True
|
||||||
else:
|
else:
|
||||||
for line in self.order_id.order_line:
|
for line in self.order_id.order_line:
|
||||||
# Iterate through the lines on the SO in order until we find this one in the list
|
|
||||||
found = False
|
found = False
|
||||||
if line == self:
|
if line == self:
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
continue
|
continue
|
||||||
# If we've hit the next section without returning False, all lines in this section were delivered
|
|
||||||
if found and line.display_type == 'line_section':
|
if found and line.display_type == 'line_section':
|
||||||
self.is_fully_delivered = True
|
return True
|
||||||
return
|
val = single_line_func(self)
|
||||||
if line.qty_to_deliver > 0:
|
if not val:
|
||||||
self.is_fully_delivered = False
|
return val
|
||||||
return
|
return True
|
||||||
self.is_fully_delivered = True
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,25 @@ class FSMVisitTest(TransactionCase):
|
||||||
|
|
||||||
self.assertTrue(visit.is_completed)
|
self.assertTrue(visit.is_completed)
|
||||||
|
|
||||||
|
def test_visit_shows_invoiced_when_invoiced(self):
|
||||||
|
so = self.generate_sale_order()
|
||||||
|
visit = self.generate_visit(so)
|
||||||
|
self.add_service_so_line(so, task=True)
|
||||||
|
so.action_confirm()
|
||||||
|
task = so.order_line.filtered(lambda l: l.task_id).task_id
|
||||||
|
task.action_fsm_validate()
|
||||||
|
|
||||||
|
self.invoice_sale_order(so)
|
||||||
|
|
||||||
|
self.assertTrue(visit.is_invoiced)
|
||||||
|
|
||||||
|
def invoice_sale_order(self, so):
|
||||||
|
wiz = self.env['sale.advance.payment.inv'].with_context({'active_ids': [so.id]}).create({})
|
||||||
|
wiz.create_invoices()
|
||||||
|
inv = so.invoice_ids[-1]
|
||||||
|
inv.action_post()
|
||||||
|
return inv
|
||||||
|
|
||||||
def generate_visit(self, sale_order, label="Test Label"):
|
def generate_visit(self, sale_order, label="Test Label"):
|
||||||
return self.env['bemade_fsm.visit'].create([{
|
return self.env['bemade_fsm.visit'].create([{
|
||||||
'sale_order_id': sale_order.id,
|
'sale_order_id': sale_order.id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue