mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] Allow Multiple SP's From SO Line
[IMP] Simplify [IMP] Product ID [IMP] Indents Indent Update agreement_legal_sale/models/sale_order.py Co-Authored-By: Daniel Reis <dreis@opensourceintegrators.com> Update agreement_legal_sale/models/sale_order.py Co-Authored-By: Daniel Reis <dreis@opensourceintegrators.com> [IMP] Daniel Changes
This commit is contained in:
committed by
Patrick Wilson
parent
65a2def28f
commit
01a816bcfe
@@ -12,6 +12,7 @@
|
|||||||
'depends': [
|
'depends': [
|
||||||
'agreement_legal',
|
'agreement_legal',
|
||||||
'agreement_sale',
|
'agreement_sale',
|
||||||
|
'agreement_serviceprofile'
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'views/agreement.xml',
|
'views/agreement.xml',
|
||||||
|
|||||||
@@ -17,34 +17,49 @@ class SaleOrder(models.Model):
|
|||||||
res = super(SaleOrder, self)._action_confirm()
|
res = super(SaleOrder, self)._action_confirm()
|
||||||
for order in self:
|
for order in self:
|
||||||
if order.agreement_template_id:
|
if order.agreement_template_id:
|
||||||
order.agreement_id = order.agreement_template_id.copy(default={
|
order.agreement_id = order.\
|
||||||
'name': order.name,
|
agreement_template_id.copy(default={
|
||||||
'code': order.name,
|
'name': order.name,
|
||||||
'is_template': False,
|
'code': order.name,
|
||||||
'sale_id': order.id,
|
'is_template': False,
|
||||||
'partner_id': order.partner_id.id,
|
'sale_id': order.id,
|
||||||
'analytic_account_id': order.analytic_account_id and
|
'partner_id': order.partner_id.id,
|
||||||
order.analytic_account_id.id or False,
|
'analytic_account_id': order.analytic_account_id and
|
||||||
})
|
order.analytic_account_id.id or False,
|
||||||
|
})
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
# Create agreement line
|
# Create agreement line
|
||||||
self.env['agreement.line'].create({
|
self.env['agreement.line'].\
|
||||||
'product_id': line.product_id.id,
|
create(self._get_agreement_line_vals(line))
|
||||||
'name': line.name,
|
# Create SP's based on product_id config
|
||||||
'agreement_id': order.agreement_id.id,
|
if line.product_id.is_serviceprofile:
|
||||||
'qty': line.product_uom_qty,
|
self.create_sp_qty(line, order)
|
||||||
'sale_line_id': line.id,
|
|
||||||
'uom_id': line.product_uom.id
|
|
||||||
})
|
|
||||||
# If the product creates service profiles, create one
|
|
||||||
if line.product_id.product_tmpl_id.is_serviceprofile:
|
|
||||||
self.env['agreement.serviceprofile'].create({
|
|
||||||
'name': line.name,
|
|
||||||
'product_id': line.product_id.product_tmpl_id.id,
|
|
||||||
'agreement_id': order.agreement_id.id,
|
|
||||||
})
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def create_sp_qty(self, line, order):
|
||||||
|
""" Create line.product_uom_qty SP's """
|
||||||
|
if line.product_id.product_tmpl_id.is_serviceprofile:
|
||||||
|
for i in range(1, int(line.product_uom_qty)+1):
|
||||||
|
sp = self.env['agreement.serviceprofile'].\
|
||||||
|
create(self._get_sp_vals(line, order, i))
|
||||||
|
|
||||||
|
def _get_agreement_line_vals(self, line):
|
||||||
|
return {
|
||||||
|
'product_id': line.product_id.id,
|
||||||
|
'name': line.name,
|
||||||
|
'agreement_id': line.order_id.agreement_id.id,
|
||||||
|
'qty': line.product_uom_qty,
|
||||||
|
'sale_line_id': line.id,
|
||||||
|
'uom_id': line.product_uom.id
|
||||||
|
}
|
||||||
|
|
||||||
|
def _get_sp_vals(self, line, order, i):
|
||||||
|
return {
|
||||||
|
'name': line.name + ' ' + str(i),
|
||||||
|
'product_id': line.product_id.product_tmpl_id.id,
|
||||||
|
'agreement_id': order.agreement_id.id,
|
||||||
|
}
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
# If sale_timesheet is installed, the _action_confirm()
|
# If sale_timesheet is installed, the _action_confirm()
|
||||||
# may be setting an Analytic Account on the SO.
|
# may be setting an Analytic Account on the SO.
|
||||||
|
|||||||
Reference in New Issue
Block a user