Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Core/Model/Base/PurchaseDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public function getNewProductLine($reference)
$newLine->recargo = $product->getTax()->recargo;
$newLine->referencia = $variant->referencia;

$this->setLastSupplierPrice($newLine);

// allow extensions
$this->pipe('getNewProductLine', $newLine, $variant, $product);
}
Expand Down Expand Up @@ -208,27 +206,4 @@ public function updateSubject(): bool
$proveedor = new Proveedor();
return $this->codproveedor && $proveedor->load($this->codproveedor) && $this->setSubject($proveedor);
}

/**
* Sets the last price and discounts from this supplier.
*
* @param BusinessDocumentLine $newLine
*/
protected function setLastSupplierPrice(&$newLine): void
{
$where = [
new DataBaseWhere('codproveedor', $this->codproveedor),
new DataBaseWhere('referencia', $newLine->referencia),
new DataBaseWhere('precio', 0, '>')
];
$orderBy = ['coddivisa' => 'DESC'];
foreach (ProductoProveedor::all($where, $orderBy) as $prod) {
if ($prod->coddivisa === $this->coddivisa || $prod->coddivisa === null) {
$newLine->dtopor = $prod->dtopor;
$newLine->dtopor2 = $prod->dtopor2;
$newLine->pvpunitario = $prod->precio;
return;
}
}
}
}
33 changes: 0 additions & 33 deletions Core/Model/ProductoProveedor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use FacturaScripts\Core\Template\ModelClass;
use FacturaScripts\Core\Template\ModelTrait;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Lib\CostPriceTools;
use FacturaScripts\Dinamic\Model\Divisa as DinDivisa;
use FacturaScripts\Dinamic\Model\Producto as DinProducto;
use FacturaScripts\Dinamic\Model\Proveedor as DinProveedor;
Expand Down Expand Up @@ -191,36 +190,4 @@ public function url(string $type = 'auto', string $list = 'List'): string
{
return $this->getVariant()->url($type);
}

/**
* This method is called after a record is deleted on the database (delete).
*/
protected function onDelete(): void
{
CostPriceTools::update($this->getVariant());

parent::onDelete();
}

/**
* This method is called after a new record is saved on the database (saveInsert).
*/
protected function onInsert(): void
{
CostPriceTools::update($this->getVariant());

parent::onInsert();
}

/**
* This method is called after a record is updated on the database (saveUpdate).
*/
protected function onUpdate(): void
{
if ($this->isDirty('neto')) {
CostPriceTools::update($this->getVariant());
}

parent::onUpdate();
}
}
9 changes: 8 additions & 1 deletion Core/Worker/PurchaseDocumentWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use FacturaScripts\Dinamic\Model\PedidoProveedor;
use FacturaScripts\Dinamic\Model\PresupuestoProveedor;
use FacturaScripts\Dinamic\Model\ProductoProveedor;
use FacturaScripts\Core\Lib\CostPriceTools;
use FacturaScripts\Dinamic\Model\Variante;

class PurchaseDocumentWorker extends WorkerClass
{
Expand Down Expand Up @@ -77,7 +79,12 @@ public function run(WorkEvent $event): bool
$product->idproducto = $line->idproducto;
$product->precio = $line->pvpunitario;
$product->referencia = $line->referencia;
$product->save();
if ($product->save()) {
$variant = $product->getVariant();
if ($variant->id) {
CostPriceTools::update($variant);
}
}
}
}

Expand Down
Loading