Skip to content

Commit

Permalink
[REF] mrp_production_batch: commit reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed Feb 2, 2024
1 parent 58583ad commit 06db74e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
45 changes: 22 additions & 23 deletions mrp_production_batch/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def mrp_production_batch_create_wizard_action(self):
def _action_generate_consumption_wizard(self, consumption_issues):
if not self.env.context.get("mrp_production_batch_create"):
return super()._action_generate_consumption_wizard(consumption_issues)

Check warning on line 159 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L159

Added line #L159 was not covered by tests
if self.bom_id.bom_line_ids.product_id.ids != self.move_raw_ids.product_id.ids:
if self.bom_id.bom_line_ids.product_id != self.move_raw_ids.product_id:
raise ValidationError(

Check warning on line 161 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L161

Added line #L161 was not covered by tests
_(
"A problem has been detected in production %s. Make sure you "
Expand Down Expand Up @@ -200,28 +200,27 @@ def action_view_production_batch(self):
"res_id": self.production_batch_id.id,
}

# TODO: Refactor translation management and raise of "You need to supply..."
def action_check_with_batch(self):
self.ensure_one()
try:
with self.env.cr.savepoint():
self_wc = self.with_context(mrp_production_batch_create=True)
lot = self_wc.env["stock.production.lot"].create(
{
"name": "",
"product_id": self.product_id.id,
"company_id": self.company_id.id,
}
)
self_wc.lot_producing_id = lot.id
self_wc.button_mark_done()
raise FakeException("")
except FakeException:
self.is_ready_to_produce = True
self.error_message = False
except (UserError, ValidationError) as e:
self.is_ready_to_produce = False
self.error_message = e.name
def action_produce_batch(self):
for rec in self:
try:
with rec.env.cr.savepoint():
self_wc = rec.with_context(mrp_production_batch_create=True)
lot = self_wc.env["stock.production.lot"].create(

Check warning on line 208 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L205-L208

Added lines #L205 - L208 were not covered by tests
{
"name": "",
"product_id": rec.product_id.id,
"company_id": rec.company_id.id,
}
)
self_wc.lot_producing_id = lot.id
self_wc.button_mark_done()
raise FakeException("")

Check warning on line 217 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L215-L217

Added lines #L215 - L217 were not covered by tests
except FakeException:
rec.is_ready_to_produce = True
rec.error_message = False
except (UserError, ValidationError) as e:
rec.is_ready_to_produce = False
rec.error_message = e.name

Check warning on line 223 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L219-L223

Added lines #L219 - L223 were not covered by tests

def create_batch_lot_by_bom(self):
self.ensure_one()

Check warning on line 226 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L226

Added line #L226 was not covered by tests
Expand Down
53 changes: 22 additions & 31 deletions mrp_production_batch/models/mrp_production_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def action_check(self):
self.ensure_one()

Check warning on line 125 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L125

Added line #L125 was not covered by tests
productions = self.production_ids.filtered(lambda r: not r.is_ready_to_produce)
init_production_count = len(productions)
for production in productions:
production.action_check_with_batch()
productions.action_produce_batch()

Check warning on line 128 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L127-L128

Added lines #L127 - L128 were not covered by tests
final_production_count = len(
self.production_ids.filtered(lambda r: not r.is_ready_to_produce)
)
Expand All @@ -139,31 +138,27 @@ def action_check(self):

def _check_unique_serial_lot_in_batch(self):
for rec in self:
serial_lots = []
lot_production_map = {}

Check warning on line 141 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L141

Added line #L141 was not covered by tests
for production in rec.production_ids:
serial_move_line = production.move_raw_ids.filtered(
for move_line in production.move_raw_ids.filtered(
lambda x: x.product_id.tracking == "serial"
).move_line_ids
serial_lot_ids = serial_move_line.mapped("lot_id").ids
serial_lots.extend(serial_lot_ids)
for lot in serial_lots:
if serial_lots.count(lot) > 1:
move = (
self.env["stock.move.line"]
.search([("lot_id", "=", lot)])
.filtered(
lambda x: x.move_id.raw_material_production_id
in rec.production_ids
).move_line_ids:
lot_id = move_line.lot_id.id

Check warning on line 146 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L146

Added line #L146 was not covered by tests
if lot_id in lot_production_map:
dup_production, dup_product = lot_production_map[lot_id]
raise ValidationError(

Check warning on line 149 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L148-L149

Added lines #L148 - L149 were not covered by tests
_(
"The following productions [%s, %s] are using the "
"component %s with the same serial number. Please "
"make sure that the serial numbers are unique."
)
% (
dup_production.display_name,
production.display_name,
dup_product.display_name,
)
)
.move_id
)
raise ValidationError(
_(
"The following productions are using the same serial number in"
" some of their components: %s"
% move.mapped("raw_material_production_id.display_name")
)
)
lot_production_map[lot_id] = (production, move_line.product_id)

Check warning on line 161 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L161

Added line #L161 was not covered by tests

def action_done(self):
self.ensure_one()
Expand Down Expand Up @@ -205,7 +200,7 @@ def action_view_production_ready(self):
action["domain"] = [("id", "in", self.ready_production_ids.ids)]
return action

Check warning on line 201 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L198-L201

Added lines #L198 - L201 were not covered by tests

def get_user_timezone_datetime(self):
def get_user_locale_tz_datetime_string(self, date):
self.ensure_one()
lang = self.env["res.lang"].search([("code", "=", self.env.user.lang)])

Check warning on line 205 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L204-L205

Added lines #L204 - L205 were not covered by tests
datetime_format = " ".join(
Expand All @@ -217,19 +212,15 @@ def get_user_timezone_datetime(self):
),
)
)
timezone = self._context.get("tz") or self.env.user.partner_id.tz or "UTC"
self_tz = self.with_context(tz=timezone)
return fields.Datetime.context_timestamp(
self_tz, fields.Datetime.from_string(self.create_date)
).strftime(datetime_format)
return fields.Datetime.context_timestamp(self, date).strftime(datetime_format)

Check warning on line 215 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L215

Added line #L215 was not covered by tests

@api.depends("name", "state")
def name_get(self):
result = []

Check warning on line 219 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L219

Added line #L219 was not covered by tests
for rec in self:
if rec.state == "draft":
state = _("Draft")
user_datetime = rec.get_user_timezone_datetime()
user_datetime = rec.get_user_locale_tz_datetime_string(rec.create_date)
name = "%s [%s] %s" % (

Check warning on line 224 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L222-L224

Added lines #L222 - L224 were not covered by tests
state,
user_datetime,
Expand Down
2 changes: 1 addition & 1 deletion mrp_production_batch/views/mrp_production_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</xpath>
<field name="confirm_cancel" position="before">
<button
name="action_check_with_batch"
name="action_produce_batch"
type="object"
string="Check Production"
class="oe_highlight"
Expand Down

0 comments on commit 06db74e

Please sign in to comment.