Skip to content

Commit

Permalink
manage proper copy of LR
Browse files Browse the repository at this point in the history
duplicate LR lines but not the sources.
  • Loading branch information
gurneyalex committed Nov 6, 2014
1 parent 65baeb2 commit ed13df1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
47 changes: 10 additions & 37 deletions logistic_requisition/model/logistic_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def get_partner_requisition(self):
'Reference',
required=True,
readonly=True,
default='/')
default='/',
copy=False)
# Not intended to match OpenERP origin field convention.
# Source comes from paper
source_document = fields.Char(
Expand Down Expand Up @@ -129,7 +130,8 @@ def get_partner_requisition(self):
'logistic.requisition.line',
'requisition_id',
string='Products to Purchase',
states={'done': [('readonly', True)]})
states={'done': [('readonly', True)]},
copy=True)
state = fields.Selection(
[('draft', 'Draft'),
('confirmed', 'Confirmed'),
Expand All @@ -139,7 +141,8 @@ def get_partner_requisition(self):
string='State',
readonly=True,
required=True,
default='draft')
default='draft',
copy=False)
sourced = fields.Float(
compute='_get_sourced',
string='Sourced')
Expand Down Expand Up @@ -229,16 +232,6 @@ def create(self, vals):
vals['name'] = seq_obj.get('logistic.requisition') or '/'
return super(LogisticsRequisition, self).create(vals)

def copy(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
default.update({
'state': 'draft',
'name': '/',
})
return super(LogisticsRequisition, self
).copy(cr, uid, id, default=default, context=context)

@api.onchange('partner_id')
def onchange_partner_id(self):
"""We take the pricelist of the chosen partner"""
Expand Down Expand Up @@ -326,7 +319,8 @@ class LogisticsRequisitionLine(models.Model):
name = fields.Char(
u'Line N°',
readonly=True,
default='/')
default='/',
copy=False)
requisition_id = fields.Many2one(
'logistic.requisition',
'Requisition',
Expand Down Expand Up @@ -400,7 +394,8 @@ class LogisticsRequisitionLine(models.Model):
"Sourced: The line has been sourced from procurement or warehouse"
"\nQuoted: Quotation made for the line\n"
"Cancelled: The requisition has been cancelled",
default='draft'
default='draft',
copy=False
)
currency_id = fields.Many2one(
related='requisition_id.currency_id',
Expand Down Expand Up @@ -553,19 +548,6 @@ def view_price_by_location(self):
'type': 'ir.actions.act_window',
}

def copy_data(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
std_default = {
'logistic_user_id': False,
'name': False,
'cost_estimate_id': False,
'source_ids': False,
}
std_default.update(default)
return super(LogisticsRequisitionLine, self).copy_data(
cr, uid, id, default=std_default, context=context)

@api.model
def _message_get_auto_subscribe_fields(self, updated_fields,
auto_follow_fields=None):
Expand Down Expand Up @@ -1058,15 +1040,6 @@ def _get_total_cost(self):
for line in self:
line.total_cost = line.unit_cost * line.proposed_qty

def copy_data(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
std_default = {
}
std_default.update(default)
return super(LogisticsRequisitionSource, self).copy_data(
cr, uid, id, default=std_default, context=context)

@api.onchange('dispatch_location_id')
def onchange_dispatch_location_id(self):
""" Get the address of the location and write it in the
Expand Down
11 changes: 11 additions & 0 deletions logistic_requisition/test/requisition_create_cost_estimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@
source2_id = ref("logistic_requisition_source_cost_estimate_02")
check_line(self, cr, uid, source1_id)
check_line(self, cr, uid, source2_id)
-
When I duplicate the LR
-
!python {model: logistic.requisition, id: logistic_requisition_cost_estimate_01}: |
copy = self.copy()
assert copy.state == 'draft'
assert len(copy.line_ids) == len(self.line_ids)
my_line_ids = set((line.id for line in self.line_ids))
for line in copy.line_ids:
assert line.id not in my_line_ids
assert not line.source_ids

0 comments on commit ed13df1

Please sign in to comment.