How to use allocate_id method in Slash

Best Python code snippet using slash

kits_reel_allocate_line.py

Source:kits_reel_allocate_line.py Github

copy

Full Screen

1from odoo import models,fields,api2class kits_reel_allocate_line(models.Model):3 _name = 'kits.reel.allocate.line'4 _description = 'Reel Allocate Lines'5 _rec_name = 'product_id'6 allocate_id = fields.Many2one('kits.reel.allocate','Reel Allocation',ondelete="cascade")7 alternate_allocate_id = fields.Many2one('kits.reel.allocate','Alternate Reel Allocation',ondelete="cascade")8 9 product_id = fields.Many2one('product.product','Product',ondelete='restrict')10 mo_id = fields.Many2one('mrp.production','Manufacturing',ondelete='restrict')11 lot_id = fields.Many2one("stock.production.lot",'Lot Number',ondelete='restrict')12 component_line_id = fields.Many2one('stock.move','Component Line',ondelete='cascade')13 qty_needed = fields.Float('Quantity Needed',related="component_line_id.product_qty")14 qty_allocated = fields.Float('Allocated Quantity')15 # wh_quantity = fields.Float('Available Qty',compute="_compute_wh_quantity")16 wh_quantity = fields.Float('Available Qty',related='lot_id.product_qty')17 allowed_alternate_product_ids = fields.Many2many('product.product','reel_allocate_line_alternate_products_rel','reel_allocate_line_id','product_product_id','Alternate products',compute="_compute_allowed_alternate_product_ids",store=True,compute_sudo=True)18 # For Lot Allocation19 quant_id = fields.Many2one('stock.quant','Allocated Stock')20 location_src_id = fields.Many2one('stock.location','Source Location',ondelete="restrict")21 move_line_id = fields.Many2one('stock.move.line','Move Line',ondelete="restrict")22 # @api.depends('product_id','allocate_id','alternate_allocate_id')23 # def _compute_wh_quantity(self):24 # for record in self:25 # allocate_id = record.allocate_id or record.alternate_allocate_id or False26 # total_available = 027 # if allocate_id:28 # quant_ids = self.env['stock.quant'].search([('product_id','=',allocate_id.product_id.id),('on_hand','=',True),('location_id','=',allocate_id.replenishment_id.location_id.id),('quantity','>=',1)])29 # total_available = sum(quant_ids.mapped('quantity'))30 # record.wh_quantity = total_available31 32 @api.depends('product_id','product_id.mt_product_alternative_ids')33 def _compute_allowed_alternate_product_ids(self):34 for record in self:35 record.allowed_alternate_product_ids = [(6,0,record.product_id.mt_product_alternative_ids.mapped('mt_product_id').ids)]36 @api.onchange('product_id')37 def _onchange_product_id(self):38 self.ensure_one()39 template_product_ids = self.env['mrp.bom.line'].search([('product_id','=',self.product_id.id)]).mapped('bom_id').mapped('product_tmpl_id')40 41 mo_ids = self.env['mrp.production'].search([('state','in',('draft','confirmed','progress')),('product_id','in',template_product_ids.product_variant_ids.ids)])42 return {43 'domain':{'mo_id':[('id','in',mo_ids)]}44 }45 @api.model46 def create(self,vals):47 res = super(kits_reel_allocate_line,self).create(vals)48 # if res and res.component_line_id:49 # move_line_id = self.env['stock.move.line'].create({50 # 'move_id':res.component_line_id.id,51 # 'company_id':res.component_line_id.company_id.id,52 # 'date':fields.Datetime.now(),53 # 'location_dest_id':res.component_line_id.location_dest_id.id,54 # 'location_id':res.quant_id.location_id.id,55 # 'product_uom_id':res.product_id.uom_id.id,56 # 'product_uom_qty':res.qty_allocated,57 # 'product_id':res.product_id.id,58 # 'lot_id':res.lot_id.id,59 # })60 # res.move_line_id = move_line_id61 return res62 def write(self,vals):63 res = super(kits_reel_allocate_line,self).write(vals)64 return res65 def unlink(self):66 # to_delete = self.env['stock.move.line']67 # for record in self:68 # to_delete |= record.move_line_id69 res = super(kits_reel_allocate_line,self).unlink()70 # if res:71 # to_delete.unlink()...

Full Screen

Full Screen

test_create_tensor.py

Source:test_create_tensor.py Github

copy

Full Screen

...4from pandas.util.testing import assert_frame_equal5from tensorly.decomposition import tucker6from recommender_systems.tensor_decomposition import create_tensor7class TestCreateTensor(unittest.TestCase):8 def test_allocate_id(self):9 df = pd.DataFrame([['hoge_a', 'foo_a', 'bar_a'],10 ['hoge_b', 'foo_b', 'bar_a'],11 ['hoge_b', 'foo_c', 'bar_b']12 ]13 )14 df.columns = ['hoge', 'foo', 'bar']15 actual_df = df.copy()16 for col_name in ['hoge', 'foo', 'bar']:17 actual_label, actual_unique = create_tensor.allocate_id(actual_df, col_name)18 df['hoge_id'] = [0, 1, 1]19 df['foo_id'] = [0, 1, 2]20 df['bar_id'] = [0, 0, 1]21 22 assert_frame_equal(actual_df, df)23 def test_allocate_id(self):24 df = pd.DataFrame([['hoge_a', 'foo_a', 'bar_a'],25 ['hoge_b', 'foo_b', 'bar_a'],26 ['hoge_b', 'foo_c', 'bar_b']27 ]28 )29 df.columns = ['hoge', 'foo', 'bar']30 actual_df = df.copy()31 col_name = 'hoge'32 mode_member = np.array(['hoge_a', 'hoge_b', 'hoge_c'])33 actual_label, actual_unique = create_tensor.allocate_id(actual_df, col_name, mode_member)34 df['hoge_id'] = [0, 1, 1]35 36 assert_frame_equal(actual_df, df)37 def test_melting_matrix(self):38 list_x = [np.array([[5. , 4.],39 [-2.5, 0.]])40 ]41 list_expected = [np.array([[0, 0, 5.],42 [0, 1, 4.],43 [1, 0, -2.5],44 [1, 1, 0.]])45 ]46 for x, expected in zip(list_x, list_expected):47 actual = create_tensor.melting_matrix(x)48 self.assertEqual(actual.all(), expected.all())49 def test_create_tensor_from_df(self):50 df = pd.DataFrame([['hoge_a', 'foo_a', 0],51 ['hoge_b', 'foo_b', 1],52 ['hoge_b', 'foo_c', 2]53 ]54 )55 df.columns = ['hoge', 'foo', 'val']56 list_df = [df]57 list_mode = [['hoge', 'foo',]]58 list_shape = [(2, 3)]59 list_value_name = ['val']60 61 for df, mode, shape, value_name in zip(list_df, list_mode, list_shape, list_value_name):62 ## Make an actual tensor ############################63 ct = create_tensor.CreateTensor(df, value_name, mode)64 actual = ct.create_tensor_from_df(missing_val=0)65 #####################################################66 ## Make an expected tansor ##########################67 for col_name in mode:68 actual_label, actual_unique = create_tensor.allocate_id(df, col_name)69 expected = np.array([[0, 0, 0],70 [0, 1, 2]71 ]72 )73 #####################################################74 self.assertEqual(actual.all(), expected.all())75if __name__== '__main__':...

Full Screen

Full Screen

create_tensor.py

Source:create_tensor.py Github

copy

Full Screen

1import numpy as np2import pandas as pd3import tensorly as tl4def allocate_id(df, col_name, mode_member=None):5 col_name_id = col_name + '_id'6 if mode_member is not None:7 mode_member = mode_member.astype(object)8 unique = mode_member9 label = np.array([np.where(data==mode_member)[0][0] for data in df[col_name]]) 10 df[col_name_id] = list(label)11 else:12 label, unique = pd.factorize(df[col_name])13 df[col_name_id] = list(label)14 df[col_name_id] = df[col_name_id].astype(np.int64)15 return label, unique16def melting_matrix(x):17 melted = np.array([[int(i), int(j), x[i][j]] for i in range(x.shape[0]) for j in range(x.shape[1])])18 return melted19class CreateTensor:20 """21 To create the tensor to decomposite22 Attributes23 ----------24 value_name : str25 the name of data to be entries of the tensor26 mode : list 27 A column name of the dataframe28 mode_members : list of numpy.array29 The entry's label of each mode30 31 tensor : numpy.array32 tensor to be decomposed 33 dataset : pandas.dataframe34 trimed dataset that has columns of mode and entries of the tensor35 indexes : pandas.dataframe36 labels of the tensor's mode37 values : pandas.series38 entries of the tensor39 Examples40 --------41 >>> mode = ['dog', 'cat', 'monkey'] 42 >>> dog_breeds = np.array(['shiba', 'husky', 'retriever'])43 ...44 >>> mode_members = [dog_breeds, cat_breeds, monkey_breeds] 45 >>> ct = CreateTensor(df, 'average_weight', mode, mode_member)46 """47 def __init__(self, df, value_name, mode=[None], mode_members=None):48 self.df = df49 self.value_name = value_name50 self.mode = mode51 self.mode_members = mode_members 52 ## Allocate id to each mode ######################53 if mode_members != None:54 self.labels = [allocate_id(self.df, col_name, mode_member)[0] for col_name, mode_member in zip(mode, mode_members)]55 self.uniques = [allocate_id(self.df, col_name, mode_member)[1] for col_name, mode_member in zip(mode, mode_members)]56 else:57 self.labels = [allocate_id(self.df, col_name)[0] for col_name in mode]58 self.uniques = [allocate_id(self.df, col_name)[1] for col_name in mode]59 ##################################################60 self.shape = tuple([len(unique) for unique in self.uniques])61 self.tensor = np.full(self.shape, np.nan)62 def create_tensor_from_df(self, missing_val='mean'):63 self.missing_val = missing_val64 self.mode_ids = [col_name + '_id' for col_name in self.mode]65 self.dataset = self.df[self.mode_ids + [self.value_name]]66 self.indexes = self.df[self.mode_ids]67 self.values = self.df[self.value_name]68 69 self.tensor[tuple(self.indexes.values.T)] = self.values.values70 if self.missing_val == 'mean':71 self.tensor[np.isnan(self.tensor)] = np.nanmean(self.tensor)72 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful