diff --git a/purchase.py b/purchase.py index d38f831158..ee2a2d0599 100644 --- a/purchase.py +++ b/purchase.py @@ -730,6 +730,8 @@ class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin): company=self.company, from_location=self.warehouse.storage_location, to_location=self.party.supplier_location, + supplier=self.party, + delivery_address=self.party.address_get(type='delivery'), ) def create_return_shipment(self, return_moves): diff --git a/stock.py b/stock.py index 1d3f1cc047..4b9036dc48 100644 --- a/stock.py +++ b/stock.py @@ -99,6 +99,35 @@ class ShipmentInReturn: 'by a purchase.'), }) + @classmethod + def __register__(cls, module_name): + pool = Pool() + Move = pool.get('stock.move') + PurchaseLine = pool.get('purchase.line') + Purchase = pool.get('purchase.purchase') + cursor = Transaction().connection.cursor() + sql_table = cls.__table__() + move = Move.__table__() + line = PurchaseLine.__table__() + purchase = Purchase.__table__() + + # Migration from 3.8: New supplier field + cursor.execute(*sql_table.select(sql_table.supplier, + where=sql_table.supplier == Null, limit=1)) + if cursor.fetchone(): + value = sql_table.join(move, condition=( + Concat(cls.__name__ + ',', sql_table.id) == move.shipment) + ).join(line, condition=( + Concat(PurchaseLine.__name__ + ',', line.id) + == move.origin) + ).join(purchase, + condition=(purchase.id == line.purchase) + ).select(purchase.party) + cursor.execute(*sql_table.update( + columns=[sql_table.supplier], + values=[value])) + super(ShipmentInReturn, cls).__register__(module_name) + @classmethod def write(cls, *args): pool = Pool()