Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manage proper copy of LR #24

Merged
merged 2 commits into from
Nov 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 14 additions & 39 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 All @@ -161,7 +164,8 @@ def get_partner_requisition(self):
'logistic.requisition.cancel.reason',
string='Reason for Cancellation',
ondelete='restrict',
readonly=True)
readonly=True,
copy=False)

_sql_constraints = [
('name_uniq',
Expand Down Expand Up @@ -229,16 +233,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 +320,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 +395,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 All @@ -421,7 +417,8 @@ class LogisticsRequisitionLine(models.Model):
cost_estimate_id = fields.Many2one(
'sale.order',
string='Cost Estimate',
readonly=True)
readonly=True,
copy=False)

_sql_constraints = [
('name_uniq',
Expand Down Expand Up @@ -553,19 +550,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 +1042,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